0
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?

  • 2
    read doesn't remove it - echoing the unquoted $cmd with IFS set to : does – steeldriver Jun 09 '23 at 12:16
  • I think this is a combination of that and https://unix.stackexchange.com/questions/264635/when-can-i-use-a-temporary-ifs-for-field-splitting - read is not a special built-in, so setting IFS for read will not make it persist after read 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

0 Answers0