ENOSIG Discussie (threads)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash append
Op 14-01-13 17:59, H schreef:
> Hi enosiggers,
>
> I'm stuck with this simple bash script :
>
> cat append.sh
> #!/bin/bash
> set -x
> declare -gx TODO="Todo:"
> TODO+=' aap.'
> [ -f /isernie ] || (
> TODO+=' noot.'
> )
> TODO+=' mies.'
> echo "[$TODO]"
>
> Output is :
>
> ./append.sh
> + set -x
> + declare -gx TODO=Todo:
> + TODO+=' aap.'
> + '[' -f /isernie ']'
> + TODO+=' noot.'
> + TODO+=' mies.'
> + echo '[Todo: aap. mies.]'
> [Todo: aap. mies.]
>
> Afaik bash does not have name scoping.
>
> What must I do to have 'noot' appended here ?
>
> ps. this is on GNU bash, version 4.2.37(1)-release
Your problem is that TODO+=' noot.' is executed inside a subshell, as
denoted by the parenthesis ( and ) .
My solution:
#!/bin/bash
set -x
declare -gx TODO="Todo:"
TODO+=' aap.'
TODO+=$( [ -f /isernie ] || echo " noot." )
TODO+=' mies.'
echo "[$TODO]"
Follow-ups:
Gerelateerd:
- bash append, hans@xxxxxxxxxxxxxxxxxxxxx (H), 2013/01/14
[
Date Index]
[
Thread Index]