Bash: Show IFS value

From FVue
Jump to: navigation, search

Problem

How do I check the value of the IFS (Internal Field Separator) variable? The default value is space, tab and newline so echo $IFS would show me just whitespace...

Solutions

printf

$ printf %q "$IFS"
$' \t\n'

od

$ echo -n "$IFS" | od -abc
0000000  sp  ht  nl
        040 011 012
             \t  \n
0000003

set/grep

$ set | grep ^IFS
IFS=$' \t\n'

cat

$ echo -n "$IFS" | cat -vTE
 ^I$

Restore default IFS

$ IFS=$' \t\n'

Backup and restore IFS

$ OLDIFS=$IFS IFS=$'\n'
$ # do something
$ IFS=$OLDIFS

Comments

blog comments powered by Disqus