help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Is there a way to read empty string with `read`?


From: Peng Yu
Subject: [Help-bash] Is there a way to read empty string with `read`?
Date: Mon, 23 May 2016 07:18:16 -0500

Hi, The following code shows that an empty string between two TABs can
not be captured. Is there a way to let bash read empty strings between
TABs?

~$ cat main1.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
read -r a b c <<< a$'\t\t''b c'$'\t'd
echo "$a"
echo "$b"
echo "$c"

IFS=$'\t' read -r a b c <<< a$'\t\t''b c'$'\t'd
echo "$a"
echo "$b"
echo "$c"
~$ ./main1.sh
read -r a b c <<< a$'\t\t''b c'$'\t'd
echo "$a"
a
echo "$b"
b
echo "$c"
c    d

IFS=$'\t' read -r a b c <<< a$'\t\t''b c'$'\t'd
echo "$a"
a
echo "$b"
b c
echo "$c"
d

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]