I'm trying to list script's argument by printf function. Arguments are counted by iteration of $i. What should be in printf function?
I need something like
eval echo \$$i
but in printf function.
Edit: Have while cycle with iteration of $i and among other code, I have
printf "%s" $i
But, instead of $i, I need some code, that shows me value of argument.
In my case, it is name of file, and I need list them. One file in one iteration.
i=1;for arg in "$@"; do echo "$i: $arg"; ((i++)); done, iterating through the list of arguments. Is there any reason why you can't do that too?echo; use:i=1;for arg in "$@"; do printf "%s\n" "$i: $arg"; ((i++)); done. That produces the same thing as theechodoes. You can vary the formatting to suit yourself. See also my answer. It would also help if you showed enough context for what you want to do and what you have tried that we can see how to help you properly, rather than having to guess what it is you want us to help you with.printf '%q'. Be aware that this is a bashism, unavailable in POSIX printf.