If the intention is to use a single function to echo the value of different variables then you may want to look at defining the function's (local) variable as a nameref, eg:
myfunc() {
local -n ts=$1 # -n == nameref
echo "${ts}"
}
You can then pass the name of the variable to the function, eg:
echo "########## ts1"
ts1=$(date +%s)
echo "${ts1}"
myfunc ts1
echo "########## ts2"
ts2=$(date +%Y%m%d)
echo "${ts2}"
myfunc ts2
This generates:
########## ts1
1660405189
1660405189
########## ts2
20220813
20220813
One word of caution ... if the parent process uses a variable of the same name as the function (ts in this case) you can generate a circular reference error, eg:
echo "########## ts"
ts=$(date +%s)
echo "${ts}"
myfunc ts
########## ts
1660405479
-bash: local: warning: ts: circular name reference
-bash: warning: ts: circular name reference
-bash: warning: ts: circular name reference
To address this scenario consider using a variable name (in the function) that hopefully won't be used by the caller, eg:
myfunc() {
local -n _ts=$1 # maybe "_myfunc_local_ts" ?
echo "${_ts}"
}
echo "########## ts"
ts=$(date +%s)
echo "${ts}"
myfunc ts
########## ts
1660405560
1660405560