LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 09: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, 10:02 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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, 07: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:05 AM.

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
Open Source Consulting | Domain Registration