I have a bash script which I need to convert from linux to FreeBSD, but I'm obviously too stupid to read the man page in a proper way.
The script has a line along:
date +%d -r "$file"
which works fine under linux, but just gives
date: illegal time format
on FreeBSD.
The linux man page says that -r
is used to specify the referencre file:
-r, --reference=FILE
display the last modification time of FILE
What puzzles me here, is that the FreeBSD man page contains the same usage for this switch, but also provides an alternate one:
-r seconds
Print the date and time represented by seconds, where seconds is
the number of seconds since the Epoch (00:00:00 UTC, January 1,
1970; see time(3)), and can be specified in decimal, octal, or
hex.
-r filename
Print the date and time of the last modification of filename.
Obviously the above error messages results from the expectation of a UNIX timestamp as parameter for the -r
switch instead of the provided filename.
What I don't understand, is how I am supposed to make it clear that I want to use the second interpretation of the -r
switch. If it is supposed to be deduced from the context of the call, I'm confused on how to provide this context.
Can anybody please explain to me, how I am supposed to tell the date utility, which use case of the -r
switch I want to use here?
date
etc.)+%d
at the end.