Arguments & Command Exit Statusby Pigbrain

Arguments

  • parameter는 순서대로 $1, $2.. 에 할당 된다
  • $0에는 스크립트명이 들어간다

Example

test.sh
-----------------------------
	echo $0
	echo $1
	echo $2

prompt> ./test.sh apple banana
		parameter0 : ./test.sh
		parameter1 : apple
		parameter2 : banana

Command Exit Status

  • 명령어 실행이 종료되면 숫자형태의 exit status를 반환한다
  • exit status의 값
    • 0 : true / success
    • 0 외의 수 : false / failure


Numeric valueMeaning
0success
2Returned by built-in commands to indicate usage errors
126Command was found but was not executable
127Command not found
128 + NCommand died due to receiving signal number N

Example

prompt> testcommand
-bash: testcommand: command not found
prompt> echo $?
127


참고

Published 13 March 2016