I've read bash manpage and other docs, but I find the explanation a bit confusing.

I have the following simple script:



echo $2

var=A B C

echo $var

if I execute it, eg:

LANG=C ./args2 3 4
./args2: line 7: B: command not found

I really don't understand, why $2 = 4? If manual says:

If the value of IFS is null, no word splitting occurs.

The same thing with var declaration, why it complains about "B"? So there is word splitting anyway?


2 Answers 2


This section of the bash manual lays out the steps: Shell Operation

In step 3, the script is broken up into commands, arguments, etc.

  • in this step, we get the tokens "var=A", "B" and "C"
  • see section Simple Commands where it says (emphasis mine):

    A simple command is [...] just a sequence of words separated by blanks

Word splitting is not performed until expansions, step 4.

As Qudit explained, your shell split "LANG=C ./args2 3 4" into tokens before launching the command "./args2"


Before your script runs, IFS has its default value. The argument splitting is done in the bash instance in which you ran your script and it splits things normally because you haven't set IFS yet.

  • If I run on the very shell: export IFS=""; var=A B C bash: B: no se encontró la orden. It does the same thing. Why?
    – sebelk
    May 3, 2015 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .