shanenin Posted May 3, 2005 Report Share Posted May 3, 2005 (edited) below is a bash script, I copied for a book(slightly changed)for FILE in $HOME/*do cp $FILE ${HOME}/new/directory chmod a+r ${HOME}/new/directory/${FILE}doneI understand that the first line sets the variable FILE to each of the values contained in $HOMEThe third line is confusing me , why is HOME in these {}, like this {HOME} what is that accomplishing, specifically what do those backets do. Edited May 3, 2005 by shanenin Quote Link to post Share on other sites
crrj Posted May 3, 2005 Report Share Posted May 3, 2005 Shanenin,Basically what it is doing is using the value of the variable HOME. The braces keep the variable name seperate from the rest of the path to ensure that the shell doesn't treat the whole thing as the variable name.crrj. Quote Link to post Share on other sites
shanenin Posted May 3, 2005 Author Report Share Posted May 3, 2005 (edited) sure that makes sence, but why not do it to this line alsofor FILE in $HOME/*is there a logical reason why the person who made this script did not use braces in all instances of the variable HOME? Edited May 3, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted May 3, 2005 Report Share Posted May 3, 2005 is there a logical reason why the person who made this script did not use braces in all instances of the variable HOME?You'd have to ask them It wouldn't surprise me if it was habitual and the author didn't notice the inconsistency.Strictly there was no need to use braces at all in that script. In the absence of braces the shell is supposed to use the longest valid variable name. '/' isn't a valid character in a name, so there's no chance of misparsing the whole path as a variable. Still, the braces are the recommended form. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.