-1

I constantly see IFS="value" command being referred to as a means of changing the IFS (Internal Field Separator) temporarily, only for the duration of the command provided, yet there are many situations where what looks to me to be similar usage fails.

I am sure these are errors on my part, but In trying to figure out what my misunderstanding was/is, I was completely unable to find any official documentation even speaking of the existence of this feature.

Perhaps this is a true case of simply not knowing which term to search for, as perhaps there is a name for this feature that I am unaware of and was unable to find through quite a reasonable amount of searching.

I've tried searching through the BASH manual, searching for relevant sections of the posix spec, asking Bing chat and more. The only results I seem to be able to find are people referring to the features existence but never any official documentation. Outside of knowing that it must exist because it clearly works for myself and others, it feels as if this feature, or rather official documentation for this feature simply does not exist.

My question therefore to StackExchange, is what in the universe is this feature called and where is it officially documented?

I am looking for any official documentation at this point whether that be for BASH, Posix, Linux, Unix, anything.

1 Answers1

2

This is documented in the "Environment" section of the bash manual, which says:

The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described in Shell Parameters. These assignment statements affect only the environment seen by that command.

That means that the syntax you're asking about isn't specific to IFS; it holds for any variable. E.g., to set the variable HOME for a single command, we can run:

HOME=/tmp/somedir mycommand

This syntax is also documented in the bash(1) man page, which says (in the "SHELL GRAMMAR" section):

A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator.

And in the "SIMPLE COMMAND EXPANSION" section:

When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right, in the following order.

  1. The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing.

  2. The words that are not variable assignments or redirections are expanded. If any words remain after expansion, the first word is taken to be the name of the command and the remaining words are the arguments.

  3. Redirections are performed as described above under REDIRECTION.

  4. The text after the = in each variable assignment undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before being assigned to the variable.

larsks
  • 34,737
  • Thanks! Def was a "I don't know what to search for" problem. The question this is marked as a duplicate of is I think, a different question even, and despite the marking, I think I'll leave my post up incase someone who gets stuck looking for the same terms I was looking for may find it useful. Especially as I somehow did not stumble upon that post. I feel my main issue here when it came to searching was the belief that because IFS happened to be the only variable mentioned in other posts, the feature must've been specific to it. Thanks. I guess there isn't a name, but its part of a concept. – Befitting Display Name May 03 '23 at 17:40