date - How to pass a variable to the mv command to rename a file text with spaces and the variable's text in a bash (.sh) file -


i create variable , store day, date & time in it:

now=$(date "+%a %d/%m/%y% %h:%m") 

then pass $now mv command rename file.

e.g. create file named a.txt title , current date:

printf "file report (" > ~/desktop/a.txt echo $now"):\n" >> ~/desktop/a.txt   

then try rename file variable ($now) included in name:

mv ~/desktop/a.txt ~/desktop/'file report $now'.txt 

what should last line be? tried these 2 options.

mv ~/desktop/a.txt ~/desktop/'file report' $now.txt 

&

mv ~/desktop/a.txt ~/desktop/'file report'${now}.txt 

assuming reasonably bourne-like shell (such bash), variable substitution not happen inside single quotes. need use double quotes:

mv ~/desktop/a.txt "${home}/desktop/file report ${now}.txt" 

(i'm not sure whether curly braces required, can't hurt)

you need change date command avoid use of slashes. example:

now="$(date '+%a %d-%m-%y% %h:%m')" 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -