Page 2 of 2

Re: Date command lformat substitution operators, me totally

Posted: Fri Feb 07, 2014 10:00 pm
by LyleHaze
Maybe I can make it easier..

Code: Select all

11.RAM Disk:> rename qwe qwe.`date lformat %c`
RENAME: Can't rename "qwe" as "2014" because 
RENAME: object not found
You don't know why? add ECHO first

Code: Select all

11.RAM Disk:> Echo rename qwe qwe.`date lformat %c`
rename qwe qwe.Fri Feb 07 15:55:37 2014
                                               ^  ^
Now you can see what you are asking for!

Re: Date command lformat substitution operators, me totally

Posted: Fri Feb 07, 2014 11:42 pm
by nbache
BTW, another point which wasn't mentioned above:
%r fails
3.RAM Disk:> rename qwe qwe.`date lformat %r`
RENAME: Destination "PM" is not a directory.
The failure here is because the date command evaluates to something containing a space, which by the shell is seen as two separate arguments. The command actually evaluates to "rename qwe qwe.11:26:55 PM", which means "rename both qwe and qwe.11:26:55 to PM", which in AmigaOS is taken as "move them down into the directory PM", since it doesn't make sense to rename two files to the same name. And since we don't have a directory called PM, that's what it fails on.

Now, this could be remedied by enclosing your target filename with double quotes, like so:

> rename qwe "qwe.`date lformat %r`"

Then it evaluates to: rename qwe "qwe.11:26:55 PM", which is a valid file rename command - or rather, it would be, if you didn't now hit the next bump, that your target filename contains colons. So it is seen as a path specification starting with the volume name "qwe.11:", which is why that volume is requested to be inserted, and when you reject that, the command of course cannot be completed. It never goes on to realise there is one more colon, and I don't know what would have happened if it could, but that's another story altogether :-D.

Anyway, the lesson here is to always surround something with double quotes if you are not sure it will evaluate to a single, spaceless word. Even if it does, the quotes won't hurt.

Best regards,

Niels