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.

This question already has an answer here:

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 i have made a server that takes ssh comands and executes them and returns the result to the client, and it is running ok, it return what i need, so this 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?

share|improve this question

marked as duplicate by Gilles, jasonwryan, warl0ck, vonbrand, Renan Mar 29 '13 at 1:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 0 down vote accepted

Use backticks. i.e.:

var=`echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567`
share|improve this answer
    
It works! Thank you very much! –  Andreea Mar 28 '13 at 9:25
5  
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) –  Dennis Kaarsemaker Mar 28 '13 at 9:28
    
@DennisKaarsemaker Ok! I'll do that! Thank you! –  Andreea Mar 28 '13 at 9:33
3  
@DennisKaarsemaker, though backticks are obsolete and have all sort of issues, they do nest. –  Stéphane Chazelas Mar 28 '13 at 10:12
1  
@StephaneChazelas But they only nest in aspirin bottles. –  Gilles Mar 28 '13 at 23:29

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