Bash: Is it possible to declare each list item on a new line?
Give a try to this tested version:
#!/bin/bash --
for var in \
1 \
2 \
3 \
4 \
6 \
; do
printf "%s\n" "${var}"
done
the for
loop splits by default a string containing (spaces) and
\n
into separate elements.
'
used in your for
loop instructs the shell (in your version) to consider the parameter as one single value, a string containing several lines.
The test:
$ ./list.sh
1
2
3
4
6
The first version for reference:
#!/bin/bash --
listint='
1
2
3
4
6
'
for var in ${listint} ; do
printf "%s\n" "${var}"
done
The '
enable to define string over multiple lines, including the \n
.