cat > ~/test.sh << 'EOF'
#!/bin/sh
echo 1
echo 2
EOF
# cat > ~/test.sh << EOF
? #!/bin/sh
?
? echo 'This is a string'
? echo "And a $variable"
variable: Undefined variable.
# EOF
# cat > ~/test.sh << 'EOF'
? #!/bin/sh
?
? echo 'This is a string'
? echo "And a $variable"
? 'EOF'
# cat ~/test.sh
#!/bin/sh
echo 'This is a string'
echo "And a $variable"
The order does not matter. I posted above the fix with explanation in an edit. There are small changes in FreeBSD that break Linux user habits.Did you try this:
cat << EOF > ~/test.sh
'EOF'
at end, not EOF
. In Linux, EOF
will work fine.cat > ~/test.sh << 'EOF'
#!/bin/sh
echo 'This is a string'
echo "And a $variable"
EOF
cat > ~/test.sh << 'EOF'
#!/bin/sh
echo 'This is a string'
echo "And a $variable"
'EOF'
root@molly:~ # setenv var foo
root@molly:~ # cat > /tmp/test << EOF
? var=bar
? echo $var
? EOF
root@molly:~ # cat /tmp/test
var=bar
echo foo
root@molly:~ # /bin/sh
# var=foo
# cat > /tmp/test << EOF
> var=bar
> echo $var
> EOF
# cat /tmp/test
var=bar
echo foo
# ^D
root@molly:~ # bash
[root@molly ~]# var=foo
[root@molly ~]# cat > /tmp/test << EOF
> var=bar
> echo $var
> EOF
[root@molly ~]# cat /tmp/test
var=bar
echo foo
[root@molly ~]#