Grant Grant - 4 months ago 6x
Linux Question

Passing multiple variables from local bash to remote bash script without gobbling

I'm having trouble sending multiple variables to a remote bash script without gobbling occurring.

For the sake of this question the variable $timestamp contains

12-12-15 19:45:21

ssh user@serverip "/usr/path/to/$1$2 $timestamp";

I am sending 3 variables to

Two URLs with an amended file name in the form of a variable on the end and then my $timestamp variable

But on, when I try to insert $timestamp into a mysql database it only see's the first part of the date before the white space :


So my quotes around the command aren't preventing gobbling. Do I need to quote each variable separately?

ssh user@serverip "/usr/path/to/$1$2 $timestamp";

This is equivalent to this locally calling

/usr/path/to/$1$2 $timestamp

Try to quote each individual argument passed

ssh user@serverip "/usr/path/to/ '$1' '$2' '$timestamp'";

You can also print each argument in the script to see what's being passed... e.g. echo $1, etc.