robshal
1
I'm trying to create a bash function that will allow me to rename a file name emails.txt to last monday's date
renem ()
{
d=`date -d last-monday`
mv ~/emails.txt ~/myemails/$d
}
but i en up wit this error any suggestion
mv: target `2014' is not a directory
The issue is you don't quote your variable.
renem ()
{
d=$(date -d last-monday)
mv ~/emails.txt ~/myemails/"$d"
}
I would suggest something more compact like:
renem ()
{
d=$(date "+%Y%m%d" -d last-monday)
mv ~/emails.txt ~/myemails/$d
}
Which date format do you need?
date -d last-monday
will produce something like:
Mon Nov 17 00:00:00 PST 2014
You don't want to rename ~/emails.txt
to Mon Nov 17 00:00:00 PST 2014
, don't you?
If you want it that way, then you need to quote the $d variable, e.g.
mv ~/emails.txt ~/myemails/"$d"
robshal
4
yes thats how i want it show
---------- Post updated at 08:13 PM ---------- Previous update was at 07:59 PM ----------
this worked thanks alot.
got any good reading to help with learning functions?