help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] need help running a command from a bash script


From: Seth David Schoen
Subject: Re: [Help-bash] need help running a command from a bash script
Date: Mon, 8 Aug 2016 14:01:20 -0700
User-agent: Mutt/1.5.24 (2015-08-30)

Wood Peter writes:

> mycommand --option "var date1='2016-01-01T04:00:00.000Z',
> date2='2016-08-08T04:00:00.000Z'"
> 
> I'd like to run this from a bash script where the date will be a variable:
> 
> date1value=`date --date=yesterday +%FT00:00:00.000Z`
> date2value=`date --date=yesterday +%FT23:59:59.000Z`
> mycommand --option "var date1=$date1value,date2=$date2value"
> 
> The above is not working because the single quotes are missing i.e.
> date1='date1_value_goes_here'
> Also I can't do date1='$date1value' either because $ can't be inside the
> sigle quotes.

You should be able to just run

mycommand --option "var date1='$date1value',date2='$date2value'"

The $ is not considered to be "inside the single quotes" in this case
because, being quoted by the double quotes, they lose their special
meaning to the shell (but are still literally passed through to
mycommand).

bash$ foo=bar
bash$ baz=qux
bash$ echo mycommand --option "var foo='$foo',baz='$baz'"
mycommand --option var foo='bar',baz='qux'

The space between "var" and "foo" was also escaped by the double quotes
in this case, so that entire string will be provided as a single
command-line parameter.

-- 
Seth David Schoen <address@hidden>      |  No haiku patents
     http://www.loyalty.org/~schoen/        |  means I've no incentive to
  8F08B027A5DB06ECF993B4660FD4F0CD2B11D2F9  |        -- Don Marti



reply via email to

[Prev in Thread] Current Thread [Next in Thread]