Tuesday, December 20, 2011

Linux - variables inside strings

http://systemsboy.com/2006/11/using-ssh-to-send-variables-in-scripts.html

I needed to execute a remote command through ssh, and I used the proposed solution (something like this)

cmd=`ssh $1 "/usr/lib/postgresql/9.1/bin/pg_ctl start -D $2 2>/dev/null 1>/dev/null < /dev/null &"`
echo $cmd


Notice the back quote or back tick (or grave)

On this respect:

The back quote is not used for quoting characters. That character is used for command substitution, where the characters between them are executed by the shell and the results is inserted on that line.

Example:
% echo the date is `date`
 
More about quotes on scripts:
http://www.grymoire.com/Unix/Quote.html 

 

 
 

No comments:

Post a Comment