Odd Behaviour for Set and IFS variable

Ok, so I'm playing around with delimters and reading files. and I came across this behaviour that I thought was a bit odd, regarding how the set command takes values... If I run this: IFS=$'-' #Assigns the - as the default delimiter for bash set I-love-my-gf-a-lot #uses set to put a bunch of text into memory. separated by the - echo $1 I love my gf a lot # this is the output when doing echo $1 echo $2 # I get no output. Nothing was assigned to it. Same goes for $3, $4, or $5... The entire line, (minus the dashes) was put into $1. But when I assign the same exact line to a variable like this: cheesy_line="I-love-my-gf-a-lot" set $cheesy_line echo $1 I echo $3 my echo $5 a etc... Why is this? Shouldn't pasing the full line to set be the same thing as setting it as a variable and then passing it to set? Why does the output stay on one line and placed into one variable ($1) with the first method? But when I assign it to a variable, and then pass it to set, does it break it up into the different $1, $2, $3, etc..?

Please show us your entire script, the command line(s) you're using to invoke it, and the output you're getting (all using CODE tags). I would guess that quoting is causing you problems, but without seeing exactly what you're doing, I'm only guessing.

1 Like