I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX compliant way of working with lists of filenames that may contain whitespace.
I am looking to modify the below example script so that it would echo
foo/target/a.jar foo/target/b.jar bar/target/lol whitespace.jar Here is the script
#!/usr/bin/env sh INPUT="foo/target/a.jar foo/target/b.jar bar/target/b.jar bar/target/lol whitespace.jar" # this would be produced by a 'ls' command # We can execute the ls within the script, if it helps dostuffwith() { echo $1; }; F_LOCATIONS=$INPUT ALL_FILES=$(for f in $F_LOCATIONS; do echo `basename $f`; done) ALL_FILES=$(echo "$ALL_FILES" | sort | uniq) for f in $ALL_FILES do fpath=$(echo "$F_LOCATIONS" | grep -m1 $f) dostuffwith $fpath done