hIghQ Plaza - meet mensan minds
« Shell Scripting Doubts »

Theme 3
Sep 8th, 2004, 2:17pm




   hIghQ Plaza - meet mensan minds
  SIG (Special Interest Groups)
  Techno Babble
  Shell Scripting Doubts
« Previous topic | Next topic »
Pages: 1  Reply Notify of repliesSend Topic Print
   Author  Topic: Shell Scripting Doubts  (Read 22 times)
Maximus Decimus
Plaza Master


member is offline



Strength and Honour

1 YIM AIM
Web Site IM

Gender: Male
Posts: 1366
Shell Scripting Doubts
« Thread started on: Jul 29th, 2004, 6:22pm »
QuoteModify

I was fooling around with a shell script which reads as

Code:
for FILE in $HOME/*.pls
do
    cp $FILE ${HOME}/source
    chmod a+r ${HOME}/source/${FILE}
done


The idea is that all *.pls files in home dir are copied to a subdir ~pranand/source and then perms are for all to read.

But what's the deal with the { and } ? When does one use braces while referencing variables? Some rules of thumb please.

PS: The script doesnt work if the second line reads as follows: chmod a+r $HOME/source/$FILE
or
chmod a+r $HOME/source/${FILE}

but if the first line is cp $FILE $HOME/source

it works fine

I can figure out that if the stmt reads
chmod a+r $HOME/source/$FILE it wont work because FILE holds the absolute path which when appended to $HOME/source points to a non existent file.



« Last Edit: Jul 29th, 2004, 6:22pm by Maximus Decimus » 148.87.1.170

A general who became a slave. A slave who became a gladiator. A gladiator who defied an emperor.
JediMaster
#Global Moderator#


member is online



use the force well, you must

YIM
Web Site IM

Gender: Male
Posts: 265
Re: Shell Scripting Doubts
« Reply #1 on: Jul 29th, 2004, 9:54pm »
QuoteModify

on Jul 29th, 2004, 6:22pm, Maximus Decimus wrote:
But what's the deal with the { and } ? When does one use braces while referencing variables? Some rules of thumb please.


The {} is used when there could be an ambiguity about how the shell can identify the variable. For example $NUMst can be refering to ${NUM}st (like in 1st if NUM=1) or NUMst variable.

Quote:
PS: The script doesnt work if the second line reads as follows: chmod a+r $HOME/source/$FILE
or
chmod a+r $HOME/source/${FILE}

but if the first line is cp $FILE $HOME/source

it works fine

I can figure out that if the stmt reads
chmod a+r $HOME/source/$FILE it wont work because FILE holds the absolute path which when appended to $HOME/source points to a non existent file.



$HOME/source/$FILE or ${HOME}/source/${FILE} will both expand to a wrong path and the script will not work in any case?? Is it working for you?
192.91.75.29

To see a World in a Grain of Sand
Pages: 1  Reply Notify of replies Send Topic Print
Admin Functions
« Previous topic | Next topic »

New Monthly Ad-Free Plan!

$6.99 Gets 50,000 Ad-Free Pageviews!
| Vacations | Hotel Reservations | DSL | National Parks | Airline Tickets | DSL Providers |

This Board Hosted For FREE By suddenlaunch
Get Your Own Free Message Board!
Hosted by www.Geocities.ws

1