Martin
Martin

Reputation: 1177

End-of-Transmission character as an IFS

I have a Bourne shell script which uses End-of-Transmission character as an IFS:

ASCII_EOT=`echo -e '\004'`
while IFS="$ASCII_EOT" read DEST PASSWORD; do
    ...
done

How does the EOT behave as an IFS? Or what kind of input might the read expect?

Upvotes: 0

Views: 90

Answers (1)

chepner
chepner

Reputation: 531390

It's an ASCII character just like ,; it just isn't printable.

$ printf 'foo\004bar' > tmp.txt
$ hexdump -C tmp.txt
00000000  66 6f 6f 04 62 61 72 0a                           |foo.bar.|
00000008
$ IFS=$(printf '\004') read f1 f2 < tmp.txt
$ echo "$f1"
foo
$ echo "$f2"
bar

Upvotes: 1

Related Questions