[Top][All Lists]

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

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

From: Greg Wooledge
Subject: Re: [Help-bash] for File in Folder_Variable_Name Expansion
Date: Tue, 17 Dec 2013 14:03:16 -0500
User-agent: Mutt/

On Tue, Dec 17, 2013 at 09:43:06AM -0900, Roger wrote:
> Think at this point, I just need to reread or study the Bash manual 
> concerning 
> encasing variable assignments using parenthesis and curly brackets (ie.  
> (,),{,} ) versus using the usual single and double quotes!

Variable assignments are simply

$ varname=content

There must not be any whitespace before or after the = sign.  Quotes may
be given if there are shell metacharacters (spaces, parentheses, etc.)
that need to be protected.

$ varname="stuff (with spaces and parens)"

Otherwise, quotes are optional.  If the content is enclosed in
parentheses, then it is an ARRAY assignment.

$ varname=(this is an array with 7 elements)
$ printf '<%s> ' "address@hidden"; echo
<this> <is> <an> <array> <with> <7> <elements> 

Normally, glob characters on the right hand side of an assignment are
not expanded.

$ foo=*
$ echo "$foo"

However, the stuff inside an array assignment IS subject to globbing and
word splitting.

$ bar=(a*)
$ echo "<${bar[0]}> <${bar[1]}> <${bar[2]}>"
<a> <abnormal> <admin>

This makes arrays a natural tool for grabbing and storing lists of files,
at least within a single directory.

reply via email to

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