GrouchyGaijin
May 13th, 2015, 10:10 AM
Rename and Variables
I was playing with rename today and thought I'd like to rename
Camera Roll.zip to
Camera-Roll.zip
(I know there are easier ways to do this. but the idea is to practice using rename.)
rename 's/Camera Roll/Camera-Roll/' *.zip worked.
So I thought how about adding the date to the end of the new file name, before the extension.
In the terminal I set:
now=$(date +"%d-%b-%Y")
Then I tried:
rename 's/Camera-Roll/Camera-Roll-"$now"/' *.zip
This gives me the error:
Global symbol "$now" requires explicit package name at (eval 1) line 1.
However, if I avoid rename and simply use:
mv Camera-Roll.zip Camera-Roll-"$now".zip
I get the desired result:
Camera-Roll-13-May-2015.zip
Could someone please exaplian:
1. What does Global symbol "$now" requires explicit package name at (eval 1) line 1. actually mean?
2. Is it possible to use variables, like the date varaible with the rename command? If so, how should I change my command?
I was playing with rename today and thought I'd like to rename
Camera Roll.zip to
Camera-Roll.zip
(I know there are easier ways to do this. but the idea is to practice using rename.)
rename 's/Camera Roll/Camera-Roll/' *.zip worked.
So I thought how about adding the date to the end of the new file name, before the extension.
In the terminal I set:
now=$(date +"%d-%b-%Y")
Then I tried:
rename 's/Camera-Roll/Camera-Roll-"$now"/' *.zip
This gives me the error:
Global symbol "$now" requires explicit package name at (eval 1) line 1.
However, if I avoid rename and simply use:
mv Camera-Roll.zip Camera-Roll-"$now".zip
I get the desired result:
Camera-Roll-13-May-2015.zip
Could someone please exaplian:
1. What does Global symbol "$now" requires explicit package name at (eval 1) line 1. actually mean?
2. Is it possible to use variables, like the date varaible with the rename command? If so, how should I change my command?