Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I go to a bash prompt and run the following command (to flush memcached):

echo "flush_all" | /usr/bin/nc 172.16.198.130 11211

it works and returns "OK".

If I put that same command in a one-line bash script:

#!/bin/sh
`echo "flush_all" | /usr/bin/nc 172.16.198.130 11211`

I get the following output:

: command not found OK

Is it trying to process "OK" as a second command? How can I prevent this (short of redirecting to /dev/null)?

share|improve this question
2  
remove the backticks. –  Stephane Chazelas Feb 13 '13 at 21:59
add comment

2 Answers

up vote 1 down vote accepted

With the backticks around the commands, you're attempting to execute the output of:
echo "flush_all" | /usr/bin/nc 172.16.198.130 11211
In your case "OK"
like already mentioned in the comments just remove the backticks.

share|improve this answer
    
Wow, now I feel dumb. :) In a prior version of the script the output was being saved to a local variable, so I had the ticks. I removed the variable logic bug left the backticks. Thanks! –  Jeremy Mullin Feb 14 '13 at 15:39
add comment

This: #!/bin/sh `echo bob` `echo jim`

Is identical to me doing this on the terminal:

# bob
bob: command not found
# jim
jim: command not found

Remove the backticks.

share|improve this answer
add comment

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.