LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rename command with external variable (https://www.linuxquestions.org/questions/linux-newbie-8/rename-command-with-external-variable-4175427639/)

Laertiades 09-17-2012 09:43 AM

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.

jschiwal 09-17-2012 10:02 AM

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.

Laertiades 09-17-2012 07:42 PM

Thank you jschiwal.


All times are GMT -5. The time now is 12:38 PM.