|
From: | John Kearney |
Subject: | Re: [Help-bash] Remove an empty (null) element in an indexed array |
Date: | Thu, 25 Apr 2013 22:22:33 +0200 |
On Wed, Apr 24, 2013 at 05:28:23PM -0400, Jerry wrote:You should use
> Assume array: declare -a FOO=(red blue green white black)
>
> Now, address@hidden would return 5
>
> If I then do: unset FOO[2}, the "green" element is erased and
> address@hidden returns 4. However, if I do:
unset 'FOO[2]'
with the quotes. If you omit the quotes, and if there just happens to
be a file named FOO2 in the current directory, then Bash will perform
globbing and convert the command into
unset FOO2
which will not do what you expected.
> echo address@hidden
Again, the quotes are very important.
echo "address@hidden"
Or better still,
printf '<%s> ' "address@hidden"; echo
I cannot duplicate your results any more than Chet could. Even in a very
old version of Bash:
imadev:~$ bash-2.05b
imadev:~$ FOO=(red orange yellow green blue indigo violet)
imadev:~$ unset 'FOO[2]'
imadev:~$ printf '<%s> ' "address@hidden"; echo
<red> <orange> <green> <blue> <indigo> <violet>
Perhaps you've got IFS set to something weird, and that together with
your missing quotes is causing unexpected oddness. But I can't guess
what value of IFS would cause it.
[Prev in Thread] | Current Thread | [Next in Thread] |