Because your $1 variable (first argument to the script) is set to XYZ=KLMN.
Just use abc_sh KLMN
and grep $1
instead of grep $XYZ
.
(Assuming we are talking about bash here)
The other alternative is defining a temporary environment variable in which case you would have to call it like this: XYZ=KLMN abc_sh
EDIT:
Found what you were using, you have to use set -k
(see SHELL BUILTIN COMMANDS in the BASH manual)
-k All arguments in the form of assignment statements are
placed in the environment for a command, not just those
that precede the command name.
So
vinko@parrot:~$ more abc
#!/bin/bash
echo $XYZ
vinko@parrot:~$ set -k
vinko@parrot:~$ ./abc XYZ=KLMN
KLMN
vinko@parrot:~$ set +k
vinko@parrot:~$ ./abc XYZ=KLMN
vinko@parrot:~$
So, the place where this was working probably has set -k
in one of the startup scripts (bashrc or profile.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…