Get Timestamp
#!/bin/bash | |
function getTimestamp() | |
{ | |
#declare a name reference | |
#The name reference should reference the first parameter | |
declare -n ts_=$1 | |
ts_=`date +"%Y%b%d_%H%M%p"` | |
} | |
function getTimestampUsingVariableFormat() | |
{ | |
#declare a name reference | |
#The name reference should reference the first parameter | |
declare -n ts_=$1 | |
declare formatMask="%Y%b%d_%H%M%p" | |
ts_=`date +"$formatMask"` | |
} | |
function getTimestampUsingVariableFormatAndEval() | |
{ | |
#declare a name reference | |
#The name reference should reference the first parameter | |
declare -n ts_=$1 | |
declare formatMask="%Y%b%d_%H%M%p" | |
declare formatTSDate=`date +"$formatMask"` | |
ts_=$(eval "echo $formatTSDate") | |
} | |
TS1='' | |
TS2='' | |
TS3='' | |
#invoke function | |
#pass variable by reference | |
getTimestamp TS1 | |
getTimestampUsingVariableFormat TS2 | |
getTimestampUsingVariableFormatAndEval TS3 | |
#display result | |
echo "Timestamp(\$TS1) is ${TS1}" | |
echo "Timestamp(\$TS2) is ${TS2}" | |
echo "Timestamp(\$TS3) is ${TS3}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment