[lug] Bash shell script question
Lee Woodworth
blug-mail at duboulder.com
Wed Feb 21 18:17:32 MST 2018
On 02/21/2018 05:56 PM, BC wrote:
>
>
> On 2/21/2018 5:47 PM, Lee Woodworth wrote:
>> On 02/21/2018 05:38 PM, BC wrote:
>>>
>>>
>>> _value="$(__get_jail_prop $_property default)"
>>>
>>>
>>
>> I don't recall the string 'default' being special to the shell in an
>> argument list. It looks to me like a second argument to the command/function.
>>
>> info bash usually has all the gory details
>
> Yeah, yeah - I've studied the bash man page (and what Google offers me) for months now.
> I'm having to learn sh scripting alongside golang. Bletch.
>
>>
>> What could happen is that since _property is not quoted, when it is empty then
>> the command expansion is equivalent to:
>> "$(__get_jail_prop default)"
>
> This I will have to chew on and study with the resources until I understand what you are
> saying... From what I can tell of the script, $_property is never empty at this point.
> I've been stepping through my Go version of the program and it this call that causes failure.
>
> Thanks. Oh, in case you couldn't tell, I'm a hobbyist.
If you change your bash from
_value="$(__get_jail_prop $_property default)"
to
_value="$(__get_jail_prop '$_property' default)"
and the behavior changes it would suggest _property is an
empty or blank string. at some point.
Oh. And when building command lines for os.Cmd make sure you have separate
slice elements for each arg so they will be passed as separate args to the
command:
property := "the prop string"
tmpdir := "value for TMPDIR in the passed environment"
cmd := &exec.Cmd{
Path: "/path/to/_get_jail_prop",
Dir: "/cd/to/this/dir/,
Args: []string{
"/path/to/_get_jail_prop",
property,
"default",
},
Env: []string{
"PATH=/usr/local/bin:/usr/bin",
"TMPDIR=" + tmpdir,
},
}
More information about the LUG
mailing list