Command-line variable assignments in Cygwin Bash not working? -


According to Section 3.7.1 of the Bash Manual, the variable assignment should be applied at the beginning of a command line

For example

  DIR = / tmp ls $ DIR  

should behave as I have written "ls / tmp" - and the variable should not continue after executing the DIR command.

Signin Bash (GNU Bash, Version 3.2.51 (24) -Relize (i686-pc-cygwin) does not appear to do so - The above order behavior Note that this is a semicolon that works ("DIR = / tmp; ls $ DIR to add" DIR = / tmp echo $ DIR "," DIR = / tmp set " Etc. It is confirmed by other tests like.

"), but leaves the defining variable after the command.

Why is it not expected?

< / Div>

This works - but not in context that you are trying to work on it.

  DIR = / tmp ls $ DIR  

Environment variable DIR is set to ls - but when the shell does not extend $ $ DIR command, the behavior of the Born Shell is like this; Corn Shell and Bash Behavior are inheritors.

You can see that the DIR is set by changing ls $ DIR to env . ; It will show an external (not built) command environment.

In this example, think about it for a moment: what you have typed is compared to 9 additional characters:

  ls / tmp  

If you want to set and remove it, then this is the trick:

  (DIR = / tmp; Ls $ DIR)  

Shell is set before evaluating ls $ DIR , but the whole command is run in a sub-shell so there is no one in it, the effect on the Incol shell.


Comments