Date command lformat substitution operators, me totally out

A forum for general AmigaOS 4.x support questions that are not platform-specific
User avatar
LyleHaze
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 525
Joined: Sat Jun 18, 2011 4:06 pm
Location: North Florida, near the Big Bend

Re: Date command lformat substitution operators, me totally

Post 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!
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: Date command lformat substitution operators, me totally

Post 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
Post Reply