Generally, I am wondering how I can pass the arguments from a terminal command to stdout. More specifically, I am using tar as part of my backup process and I would like the parameters (especially excluded dirs) to be passed to a log file. For the excluded dirs, I tried tar --show-omitted-dirs
, but that did not work as I thought.
I am new to working with bash scripts, but I read up about "$@" and figured I could write my own function
myLS() { echo "$@"; ls "$@"; }
to first echo the commands to stdout and then pass them to ls
. Piping echo
myLS() { echo "$@" | tr " " "\n"; ls "$@"; }
or using printf
myLS() { printf '%s\n' "$@"; ls "$@"; }
separates these arguments on new lines, which is what I would want on top of the log file.
While this works, I am curious if there is a preferred way to go about it, which does not require me to rewrite my own function every time I want to keep a log of the arguments I used when running a command. Both general solution and solutions specific to tar
are helpful.