Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-17-2012, 10:43 AM   #1
Registered: Jul 2012
Location: Pacific Northwest
Distribution: Arch
Posts: 59

Rep: Reputation: Disabled
rename command with external variable

I have the following bash script which accepts an argument, creates a directory with the name of the arg, rips a cd putting all files in the new directory and then compresses them. I want to rename all the created files to have the name of the arg but I can't figure out how to use a variable in the rename command. Here is my script:


case "$1" in
"" ) echo "Usage: `basename $0` new-folder"; exit $E_WRONGARGS;;
* ) ffolder=$1;;

mkdir ~/Music/$ffolder
cd ~/Music/$ffolder
cdparanoia -B
rm *00*
rename 's/\.cdda//' ~/Music/$ffolder/*.wav
#rename 's/track/$ffolder/' ~/Music/$ffolder/*.wav
oggenc -q 5 *.wav

eject /dev/cdrom

exit 0

The second rename command which is commented out is one of my failed attempts. I also tried putting {} around $ffolder and I tried making the whole regex expression a variable all to no avail. If someone could show me how to do this properly I would greatly appreciate it.
Old 09-17-2012, 11:02 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Use double quotes instead of single quotes. Single quotes will cause $ffolder to be used literally instead of being evaluated by the shell before the command is run.
Old 09-17-2012, 08:42 PM   #3
Registered: Jul 2012
Location: Pacific Northwest
Distribution: Arch
Posts: 59

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thank you jschiwal.


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
[SOLVED] find and rename command Leath Linux - Newbie 3 07-30-2012 11:36 PM
rename command does not work! wtn2die Linux - General 6 12-27-2006 12:00 PM
the rename bash command is malfunctioning nicdee Linux - General 10 04-29-2006 10:02 AM
rename reboot command coco03 Linux - General 6 04-19-2005 03:11 AM
rename with command line shanenin Linux - Software 1 09-25-2003 08:03 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:00 AM.

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