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
  • 2
    remove the backticks. Commented Feb 13, 2013 at 21:59

2 Answers 2

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.

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.

1
  • 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! Commented Feb 14, 2013 at 15:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.