[Linux] Shell: $* vs. $@
Linux에서 shell script를 사용하다 보면 $*과 $@를 쉽게 볼 수 있다.
$*: All the positional parameters (as a single word)$@: All the positional parameters (as separate strings)
차이점은 다음 예제 코드를 통해 쉽게 이해 가능하다.
#!/bin/sh # my_bash.sh echo "=================" echo "\$@ section" echo "=================" for param in "$@" do echo $param, done echo "=================" echo "\$* section" echo "=================" for param in "$*" do echo $param, done
$ ./my_bash.sh hello world shumin ================= $@ section ================= hello, world, shumin, ================= $* section ================= hello world shumin,
위 결과를 토대로 $@는 각 입력을 array 형태로 가져오는 반면, $*는 하나의 문자열로 가져오는 것을 알 수 있다.
Reference
- https://jybaek.tistory.com/477