This will print all entries on individual lines:
Uses simple parameter substitution
and ansi-style quoting. The extquote
shell option needs to be enabled in order for it to be used inside expansions. This is the default in interactive shells, but not in scripts. The expansion also needs to be quoted to preserve the newlines, of course.
Another option using an intermediate array:
pathlist=( $PATH )
prints a string of all individual array elements, separated by the first character of IFS.
exhibiting different behaviours when executed in a shell script and when executed on the command line ?
echo -e "hello\nthere"
Most probably your system is using dash
or another shell when interpreting basic shell scripts, and it has a different set of options for echo. Change your shebang from #!/bin/sh
and see what happens.