i´m new to bash and couldn`t find any fitting answer, hopefully you guys can help me. Sorry if the answer to my question is too obvious.
I want to create a function with variable number of parameters, that should be printed out with a for loop. The parameters passed are the printable Strings. The output should be the number of the "for loop" starting with 1 and then the passed argument. I can´t find the solution to say: Print the number of the iteration, then print the function parameter at position of the iteration.
I always get the error: invalid number
Please excuse the confusion. THANKS
it should look like this
SOME TEXT
1: String1
2: String2
3: String3
func() {
echo -e "SOME TEXT"
for i in "$@"; do
printf '%d: %s\n' "$i" "$@" # I also tried "${i[@]}"
done
}
func String1 String2 String3