GNU/Linux >> Linux の 問題 >  >> Linux

Bashでの$#の使用は何ですか

https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html から

<ブロック引用>

$# 10 進数の定位置パラメーターの数に展開されます。

$? 最後に実行されたフォアグラウンド パイプラインの終了ステータスに展開します。


Learn Bash in Y minutes より:

# Builtin variables:
# There are some useful builtin variables, like
echo "Last program's return value: $?"
echo "Script's PID: $$"
echo "Number of arguments passed to script: $#"
echo "All arguments passed to script: [email protected]"
echo "The script's name: $0"
echo "Script's arguments separated into different variables: $1 $2..."

$# スクリプトの引数の数を示します$? 最後のスクリプトの戻り値を表示します

引数について:echo "ARG[$#]" if より前 そして、次のようにスクリプトを実行します

script.sh 1 

出力は

ARG[1]
Usage: g old-pattern new-pattern filename

など

$? の出力 コマンドラインでも使用できます:

#shell>ls
file1.txt        g                inpu             nodes_list
#shell>echo $?
0

#shell>ls FileNameNotFound
ls: FileNameNotFound: No such file or directory
#shell> echo $?
1

Linux
  1. Bashシェルのカスタマイズ

  2. エコー$は何ですか?行う??

  3. bashの&>と>&の違いは何ですか?

  1. Bash For Loopsの「do」キーワードの目的は?

  2. PowerShell の Bash の cat -n に相当するものは何ですか?

  3. Linux での export コマンドの役割は何ですか?

  1. Readlineワードセパレーターとは何ですか?

  2. 使用している Fedora のバージョンを確認するにはどうすればよいですか?

  3. -e は bash シバンで何をしますか?