Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created March 11, 2024 23:41
Show Gist options
  • Save hnakamur/89d98c6cfdcc855995b26da725f5f734 to your computer and use it in GitHub Desktop.
Save hnakamur/89d98c6cfdcc855995b26da725f5f734 to your computer and use it in GitHub Desktop.
bash-args-array.sh
#!/bin/bash
# コマンドライン引数を配列に格納
args=("$@")
# 配列の要素を表示
for arg in "${args[@]}"; do
echo $arg
done
# 特定の要素にアクセス
echo "最初の引数: ${args[0]}"
echo "二番目の引数: ${args[1]}"
@hnakamur
Copy link
Author

$ ./bash-args-array.sh -a -b "b and c" -c
-a
-b
b and c
-c
最初の引数: -a
二番目の引数: -b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment