LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-17-2012, 10:43 AM   #1
Laertiades
Member
 
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:

#!/bin/bash

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

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
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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
Laertiades
Member
 
Registered: Jul 2012
Location: Pacific Northwest
Distribution: Arch
Posts: 59

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thank you jschiwal.
 
  


Reply


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


All times are GMT -5. The time now is 04:52 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration