Reputation: 70030
Which is the righy way to put a variable inside a command in bash
?
I'm trying with:
PORT=80
`nc -zv -w30 127.0.0.1 $PORT >> /dev/null`
but it doesn'work.
Upvotes: 0
Views: 421
Reputation: 25269
I assume you mean you want the output of the command stored in a variable. If so then you should first of all assign the command to a variable, and secondly don't send the output to /dev/null.
x=`nc -zv -w30 127.0.0.1 $PORT`
OR alternate syntax:
x=$(nc -zv -w30 127.0.0.1 $PORT)
Upvotes: 0
Reputation: 8467
>>
), just write (>
). That should work. If it's not working, something else is wrong.
PORT=80
nc -zv -w30 127.0.0.1 $PORT > /dev/null
Upvotes: 2