I have read many OLD posts about how to do this including doing the date -d xx. This does not work in AIX.
I'm trying to make a short ksh script that will take input from command line like this: ./lintime 1707858293
Then provide me the human readable output like "date" does: Tue Feb 13 16:16:24 CST 2024
Based on researching, I thought that using $1, $2..etc would read the variables in from the command line. Using that, my coding attempt was as follows:
check out the ksh documentation for printf , an example for you start with below (from a non AIX system, but from within ksh shell), adjust the format to meet your specifics
it's been awhile since my AIX days, but... a couple of REALLY old cliff notes on the subject - not ksh93 dependent:
# here's my current EPOCH time
currentEpoch=$(/usr/bin/truss /usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}')
# here we convert EPOCH back to human readable format
back2Human=$(echo "0t${currentEpoch}=Y" | /usr/bin/adb)
Things might have gotten better/easier since then...
You don't need the echo $( )
indirection.
But your mistake was to expect that the shell evaluates a $1 in a 'string in ticks'.
It would do it in a "string in quotes", but that would conflict with many things in perl.
The suggested $ARGV[0] in perl (in ' ' ) and a given $1 argument (in " ") is the proper solution.
Using perl -l a print puts a trailing "\n" (and input lines are chomp ed):
perl -le 'print scalar(localtime($ARGV[0]))' "$1"
Now you could even put this(!) shell code in " " and let the shell evaluate the $1
perl -le "print scalar(localtime($1))"
But it remains a hack, imagine $1 would have a ( character...
For a long time, AIX has included the commands ksh and ksh93. Aix ksh is ksh88?
Have you tested command ksh93? AIX has ksh = ksh88 and also ksh93
Location ksh93, I'm not sure. My guess /usr/bin/ksh93. printf T option is published in ksh93, not in ksh88.
ksh93
printf "%(%Y-%m-%d %H:%M:%S)T\n" "#1707858293"
2024-02-13 21:04:53
# need updated ksh93 before using date > 2038-01-19 ...