Is there a command like echo
that shows the arguments as they were received?
For example echo "a b" c
shows a b c
but I would like to see something like "a b" "c"
.
You could use printf
, e.g.:
$ printf ">%s<\n" "a b" c
>a b<
>c<
Or use whichever separators you like, but note that it doesn't produce shell-style quoted output like set -x
does. And it always prints the format string at least once, so printf ">%s<\n"
without other arguments produces ><
.
Or to get shell-style quoted output in Bash:
$ printf "%q\n" "a b" c
a\ b
c
The downside of %q
is that it prefers backslashes instead of quotes, so the output is ugly and harder to read than necessary.
Of course, you could also create an external script to do that, but it might too heavy a solution for your situation:
$ cat args.sh
#/bin/bash
printf "%d args: " "$#"
for x do
printf "%s " "${x@Q}" # nicer output than printf %q
done
echo
$ ./args.sh "a b" c
2 args: 'a b' 'c'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments