4 ms·
While setting IFS=$"\t\n" may make problems less likely when strings contain spaces, it's still not correct. File names (and other strings) can contain tabs an
by dap 12y ago
While setting IFS=$"\t\n" may make problems less likely when strings contain spaces, it's still not correct. File names (and other strings) can contain tabs and newlines, too. That's relatively rarer, but the quoting approach always works.
- redsymbol 12y agoHm, is that true? When I run this script: #!/bin/bash items=( 'a' 'b c' "d\te" "f\ng" ) echo "Unquoted:" for item in ${items[@]}; do echo -e ". $item" done echo "Quoted:" for item in "${items[@]}"; do echo -e ". $item" done set -euo pipefail IFS=$'\n\t' echo "Unquoted strict mode:" for item in ${items[@]}; do echo -e ". $item" done ... I get this output: Unquoted: . a . b . c . d e . f g Quoted: . a . b c . d e . f g Unquoted strict mode: . a . b c . d e . f g Note the output for "Quoted" and "Unquoted strict mode" are identical. (GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu))