Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell script parameters

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi i am currently writing a shell script, to do a batch rename of files. I want to execute the script and pass as parameters the files i want to rename, with the last being the target to rename the rest ie

fileRename fred.doc barney.txt simon.dnr *.com

to rename all files to .com
i need to validate the parameters to ensure no files apart from the target contain a '*' how can i do this. i tried using a if statement but cant get it to recognise a literal '*'. can i do this using a case statement?
thanks for any help, brian
 
if all the files have a "." in the filename, create a script called fileRename and pass the filenames as variables into the script like this:

$ ls -l test*
-rw-r--r-- 1 user staff 0 May 21 15:07 test1.doc
-rw-r--r-- 1 user staff 0 May 21 15:07 test2.txt
-rw-r--r-- 1 user staff 0 May 21 15:07 test3.htm
$ fileRename test1.doc test2.txt test3.htm
test1.doc test2.txt test3.htm
sssaix01 $ ls -l test*
-rw-r--r-- 1 user staff 0 May 21 15:07 test1.com
-rw-r--r-- 1 user staff 0 May 21 15:07 test2.com
-rw-r--r-- 1 user staff 0 May 21 15:07 test3.com
$

the script could look something like this:

list=$*
echo $list
for i in `echo $list` ; do
x=`echo $i | cut -d . -f 1`
mv $i $x.com
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top