For a given file one may issue the bash command:
ls -la --full-time --time-style long-iso --time-style=+"%Y-%m-%d %H:%M:%S" file
This works of course.
I have a larger script in which I would like to define the time-style and to reference it multiple times:
TMP_TIME_STYLE="--full-time --time-style long-iso --time-style=+""%Y-%m-%d %H:%M:%S"""
Executing the command
ls -la ${TMP_TIME_STYLE} file
results in the error message:
ls: accessing '%Y-%m-%d' is not possible: no such file or directory.
It seems that not all the options in ${TMP_TIME_STYLE} are passed to ls.
I already tried to put additional "" just in front of %Y-%m-%d and immediately behind %H:%M:%S, however the same error message.
How to safely pass the contents of ${TMP_TIME_STYLE} to ls?
alias. e.g.alias lst='ls -la --full-time --time-style long-iso --time-style=+"%Y-%m-%d %H:%M:%S"'. Thenlst file. – pLumo Nov 26 '21 at 09:27TMP_TIME_STYLE: inTMP_TIME_STYLE="... --time-style=+""%Y-%m-..., the second and third quotes just close and reopen the quoted string, the result would be the same withTMP_TIME_STYLE="...--time-style=+%Y-%m-%d %H:%M:%S". Regardless, the quotes wouldn't help, this is what everyone tries and what is explained in the linked question. You could doTIME_STYLE="--time-style=+%Y-%m-%d %H:%M:%S"andls -l ... "$TIME_STYLE"though, but you can't have the string split on one space but not another. – ilkkachu Nov 26 '21 at 09:30shopt -s expand_aliases). A function might be better here though. – ilkkachu Nov 26 '21 at 09:34