help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] for File in Folder_Variable_Name Expansion


From: Chris Down
Subject: Re: [Help-bash] for File in Folder_Variable_Name Expansion
Date: Mon, 16 Dec 2013 18:22:44 +0800
User-agent: Mutt/1.5.22 (2013-10-16)

On 2013-12-15 18:23:37 -0900, Roger wrote:
> The following performs correctly, however I'm not used to seeing variable 
> assignments encased in parenthesis!
> 
> $ FOLDER=( ${HOME}/Books/Learning\ C/cse142/Lecture1/Files/slides/ ); for 
> file in "${FOLDER}"/*.jpg; do echo "${file}"; done

In your example, $FOLDER becomes an array with a single element.

It seems that someone thought that they would use an array with a single
element, but it's not required -- you can remove the parentheses and it
still works, because bash selects the first index if none is given
(because all variables are treated as arrays in bash, see below).

    $ var=(foo bar baz)
    $ echo "$var"
    foo
    $ echo "${var[0]}"
    foo
    $ echo "${var[-1]}"
    baz
    $ var2=foo
    $ echo "${var2[1]}"

    $ echo "${var2[0]}"
    foo

Attachment: pgpOdfxOWcWf4.pgp
Description: PGP signature


reply via email to

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