Debian Codegraph @

ifs-empty.sh

raw symbols SCIP
1 #!/bin/bash
2
3 # If $IFS set, but empty,
4 #+ then "$*" and "$@" do not echo positional params as expected.
5
6 mecho () # Echo positional parameters.
7 {
8 echo "$1,$2,$3";
9 }
10
11
12 IFS="" # Set, but empty.
13 set a b c # Positional parameters.
14
15 mecho "$*" # abc,,
16 # ^^
17 mecho $* # a,b,c
18
19 mecho $@ # a,b,c
20 mecho "$@" # a,b,c
21
22 # The behavior of $* and $@ when $IFS is empty depends
23 #+ on which Bash or sh version being run.
24 # It is therefore inadvisable to depend on this "feature" in a script.
25
26
27 # Thanks, Stephane Chazelas.
28
29 exit