Featured post
shell - What is the internal processing of $* and $@ -
actually, understand use of $* , $@.
for example, if run script using: my_script *
then, one_file in $@ each file one_file processing.
there space(s) in filenames, one_file correct filename.
if, however, using one_file in $*, story different.
think guys understand difference , not need go further.
now, interested how.
how kornshell (ksh) interprets my_scrpt *
, pass filenames $@ correctly
, pass filenames $*.
for example, when ksh see my_script *
, put filenames 1 one array,
, put array[1][2][3]... $@ processing ?
and, when seeing $*, concat
filename1+space+filename2+space+... ?
i know may relate more internal coding of ksh.
any insight?
for example, when korn shell see my_script *, put filenames 1 one array, , put array[1][2][3]... $@ processing ? and, when seeing $*, concat filename1+space+filename2+space+... ?
yes, pretty much.
one important thing realize here there 2 separate processes involved: calling shell, expands my_script *
myscript arg1 arg2 arg3
, subprocess gets array of arguments. if subprocess ksh
(or sh
, bash
, or similar shell) $*
syntax "get argv[1...] concatenated string" while $@
syntax "get argv[1...] array". it's important note $*
, $@
meaningfully different when quoted.
in bash, cousin of ksh, idea of array variables has been generalized. (perhaps ksh has done -- haven't used ksh decade...)
in bash, creates array of 3 elements called a
. note first element contains space:
[~]$ a=("foo bar" baz quux) [~]$ in ${a[*]}; echo $i; done foo bar baz quux [~]$ in ${a[@]}; echo $i; done foo bar baz quux [~]$ in "${a[*]}"; echo $i; done foo bar baz quux [~]$ in "${a[@]}"; echo $i; done foo bar baz quux
as can see example, "${a[*]}"
concatenates array while "${a[@]}"
gives individual elements.
- Get link
- X
- Other Apps
Comments
Post a Comment