On Mon, Jul 28, 2008 at 11:05 PM, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On Mon, Jul 28, 2008 at 3:51 PM, Xavier <shiningxc@gmail.com> wrote:
On Mon, Jul 28, 2008 at 10:45 PM, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
aaron@gerolde:~$ [ -z foo bar baz ] -bash: [: too many arguments aaron@gerolde:~$ [ -z "foo bar baz" ] aaron@gerolde:~$
Well don't ask me to explain, but here is a closer test case I think :
[xavier@nx7400 ~]$ array=({foo,bar,baz}) [xavier@nx7400 ~]$ [ -z "${array[@]}" ] bash: [: too many arguments
Weird. I'd guess this is something to do with globbing taking priority. Seeing as this is just testing for some value, using single quotes fixes the issue.
_______________________________________________ pacman-dev mailing list pacman-dev@archlinux.org http://archlinux.org/mailman/listinfo/pacman-dev
With single quotes, I am not sure it still works correctly. [xavier@nx7400 ~]$ unset array [xavier@nx7400 ~]$ [ -z '${array[@]}' ] || echo array not empty array not empty [xavier@nx7400 ~]$ echo '${array[@]}' ${array[@]} What about handling it just like a normal variable ? [xavier@nx7400 ~]$ array=({foo,bar,baz}) [xavier@nx7400 ~]$ [ -z "$array" ] || echo array not empty array not empty [xavier@nx7400 ~]$ unset array [xavier@nx7400 ~]$ [ -z "$array" ] || echo array not empty [xavier@nx7400 ~]$