Tuesday, December 20, 2011

Linux - variables inside strings


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.

% echo the date is `date`
More about quotes on scripts:



No comments:

Post a Comment