Jump to content

Bash: Show IFS value

From FVue

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

<google uid="C01"></google>

Comments

{{#widget:DISQUS |id=fvue |uniqid=Bash: Show IFS value |url=https://fvue.nl/wiki/Bash:_Show_IFS_value }}