LDP/LDP/guide/docbook/abs-guide/ifs-empty.sh

30 lines
572 B
Bash
Raw Permalink Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2005-05-08 20:09:31 +00:00
# If $IFS set, but empty,
#+ then "$*" and "$@" do not echo positional params as expected.
2001-07-10 14:25:50 +00:00
2001-09-04 13:27:31 +00:00
mecho () # Echo positional parameters.
2001-07-10 14:25:50 +00:00
{
echo "$1,$2,$3";
}
IFS="" # Set, but empty.
set a b c # Positional parameters.
mecho "$*" # abc,,
2008-11-23 22:43:47 +00:00
# ^^
2001-07-10 14:25:50 +00:00
mecho $* # a,b,c
mecho $@ # a,b,c
mecho "$@" # a,b,c
2005-05-08 20:09:31 +00:00
# The behavior of $* and $@ when $IFS is empty depends
2008-11-23 22:43:47 +00:00
#+ on which Bash or sh version being run.
2005-05-08 20:09:31 +00:00
# It is therefore inadvisable to depend on this "feature" in a script.
2001-07-10 14:25:50 +00:00
2005-05-08 20:09:31 +00:00
# Thanks, Stephane Chazelas.
2001-07-10 14:25:50 +00:00
2008-11-23 22:43:47 +00:00
exit