LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-15-2006, 09:44 PM   #1
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Rep: Reputation: 30
& character in file/directory names


I have some shell scripts on my system that fail as soon as they encounter a file or directory name containing the & character. What is the correct way to deal with this? Should I wrap double quotes around all file names in my script?

For example, script for resizing images:

Code:
#!/bin/sh

for FILE in $*
do

        convert $FILE -resize 300x $FILE

done
This version works but it is the correct way to do it?

Code:
#!/bin/sh

for FILE in $*
do

        convert "$FILE" -resize 300x "$FILE"

done
Paddy
 
Old 03-16-2006, 12:13 AM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Use "$*" so the arguments become "$1", "$2" and so on. Why are you using $* ?
It's best to use "$@"
 
Old 03-16-2006, 12:16 AM   #3
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Original Poster
Rep: Reputation: 30
Thanks,

Whats the difference between $* and $@?

Paddy
 
Old 03-16-2006, 12:45 AM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Well, the bash manpage says that "$*" will use the first character in $IFS (which defines the characters to separate tokens in the shell) if this variable is set while "$@" will always use a space. Usually, they're the same because IFS contains a space, a tab and a newline but it's best to be sure that it will be a space and it's more standard to use "$@"
 
Old 03-16-2006, 10:41 PM   #5
paddyjoy
Member
 
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Original Poster
Rep: Reputation: 30
Thanks for the info!
 
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change file names to uppercase in a directory konramesh Linux - General 4 06-16-2009 06:13 AM
Command to find similar file names in a directory Ottoguy Linux - Newbie 4 02-02-2006 05:42 AM
Getting file names in a directory using C on linux. rajsun Programming 4 06-10-2005 12:47 AM
monitoring directory to get the modified file names appas Programming 1 09-06-2004 04:56 AM
File & directory questions Joe47 Linux - Newbie 2 02-16-2003 01:29 AM


All times are GMT -5. The time now is 04:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration