1

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)?

1

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.

  • 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
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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