/bin/bash -c 에서 -c 옵션을 붙이고 안붙이고 의 차이점은 무엇인가요?

phyljh의 이미지

/bin/bash -c test.sh

/bin/bash test.sh

두개에 차이점이 있나요?
-c를 붙이는 것들이 종종 보이는데 차이점이 무엇인지 모르겠습니다.
답변좀 부탁드립니다

김정균의 이미지

옵션에 대한 궁금증은.. man page 를 참조해 보세요.

-c string

If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

즉, -c string 에서 string 은 실행 시킬 파일이 아니라 실해 코드가 됩니다.

[user@host ~]$ bash -c "echo aaa"
aaa

string 다음에 argument 가 더 있으면, string 다음 부터 $0, $1 ... 이렇게 사용할 수 있습니다.

[user@host shm]$ bash -c "echo \$0 - \$1" aaa bbb
aaa - bbb
phyljh의 이미지

감사합니다^^