Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to write a shell script over ssh via a bash prompt. The shell, however, insists on interpreting any variable I want to write instead of writing it directly to file. For example, cat <<EOF >checkup.sh\n'$command'EOF is simply written as '' to file. How do I get $command written instead? I've tried every practical method of escaping I can think of.

If it changes anything, I'm doing it over PHP using phpseclib.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Try quoting the first EOF, e.g.,

cat <<'EOF'
>checkup.sh\n'$command'
EOF

This is explained in the bash(1) man page, in the section, Here Documents.

share|improve this answer
    
I actually needed the INVERSE of this (had a script with "EOF", needed to handle variables) and this pointed me at it. Thanks! –  Soulhuntre Dec 4 '12 at 7:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.