0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux][command] シェルスクリプト_引数_$

Last updated at Posted at 2025-06-04

引数に渡す変数(特殊パラメータ)

変数 由来 説明
$0 argument 0 - スクリプト自身のファイル名(またはコマンド名)
例: ./myscript.sh なら $0"./myscript.sh"
$1$9 positional args - スクリプトに渡された1〜9番目の引数
例: ./myscript.sh apple banana なら $1 = apple, $2 = banana
${10} positional args - 10番目以降はの引数は${10}${11}のように波括弧で囲む
例: ./myscript.sh a b c d e f g h i j k なら$10ではなく、${10} = j${11} = k
$# num of args - 渡された引数の個数
例: ./myscript.sh a b c なら $# = 3
$* all args - 全ての引数を1つの文字列として展開("$1 $2 $3..."
クォート内では「1つの単語」として扱われる
$@ all args (each) - 全ての引数を個別の文字列として展開("$1" "$2" "$3"...
for文などで引数を処理する際に便利
$? last status - 最後に実行したコマンドの終了ステータス(0=成功、0以外=失敗)
$$ PID - 現在のシェルプロセスのプロセスID(PID)

Ping-t

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?