2

I have this command succession:

echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567

and let's say it return a string like, for example "Hello...bla". On the 89.196.167.2 system, I have made a server that takes ssh commands, executes them, and returns the result to the client. That ssh program is running OK; it returns what I need, so that is not the problem.

I want to put this returned value, "Hello...bla", into a variable and use it. If I try this:

var=echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567;echo "$var"

it doesn't work. Bash returns this:

-bash: -ne: command not found

Can you please help me with a solution?

0

1 Answer 1

3

Use backticks. i.e.:

var=`echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567`
4
  • 7
    Don't use backticks. They don't nest and are not always easy to distinguish from single quotes. It's better to use $(...) instead: var=$(echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567) Mar 28, 2013 at 9:28
  • @DennisKaarsemaker Ok! I'll do that! Thank you!
    – Andreea
    Mar 28, 2013 at 9:33
  • 3
    @DennisKaarsemaker, though backticks are obsolete and have all sort of issues, they do nest. Mar 28, 2013 at 10:12
  • 1
    @StephaneChazelas But they only nest in aspirin bottles. Mar 28, 2013 at 23:29

Not the answer you're looking for? Browse other questions tagged .