line="touch : touch : test.txt"
IFS=':' read scr cmd <<< "$line"
echo $scr
echo $cmd
output:
touch
touch : test.txt
line="touch : touch : test.txt"
IFS=':'
read scr cmd <<< "$line"
echo $scr
echo $cmd
output:
touch
touch test.txt
I don't understand how the second syntax makes read remove the ':' . Any ideas?
read
doesn't remove it - echoing the unquoted$cmd
withIFS
set to:
does – steeldriver Jun 09 '23 at 12:16read
is not a special built-in, so settingIFS
for read will not make it persist afterread
returns, so the lack of quoting doesn't affect the commands after it the same way as in the second example. – muru Jun 09 '23 at 12:25