array=(item1 item2 'item3 item4' item5) echo '${array[0]}': ${array[0]} echo '${array[1]}': ${array[1]} echo '${array[2]}': ${array[2]} echo '${array[3]}': ${array[3]}
array=(item1 item2 'item3 item4' item5) echo ${#array[@]}
array=(item0 [2]=item2 [4]=item4) echo ${#array[@]} echo ${array[0]} echo ${array[1]} echo ${array[2]} echo ${array[3]} echo ${array[4]} echo ------------------ array[1]=item1 array[2]= echo ${#array[@]} echo ${array[0]} echo ${array[1]} echo ${array[2]} echo ${array[3]} echo ${array[4]} echo ------------------
array=(item1 item2 'item3 item4' item5) function echo_array_items() { echo $1 echo $2 echo $3 echo $4 echo $5 echo ------------------------ } echo Use '"${array[@]}"' echo_array_items "${array[@]}" echo Use '"${array[*]}"' echo_array_items "${array[*]}" echo Use '${array[@]}' echo_array_items ${array[@]} echo Use '${array[*]}' echo_array_items ${array[*]}
array=(item1 item2 item3) echo "${array[@]}" array2=(item_a item_b "${array[@]}") echo "${array2[@]}" array3=("${array[@]}" item_c item_d) echo "${array3[@]}" array+=(item_e item_f) echo "${array[@]}"
array=(item0 [2]=item2 [4]=item4) echo "${!array[@]}"
if grep -n test test.txt; then echo $? echo success else echo $? echo fail fi
test "$1" = "test" echo 'test コマンドの終了ステータス': $? ["$1" = "test"] echo '[ コマンドの終了ステータス':$? if ["$1" = "test"]; then echo success else echo fail fi
if [ \( "$1" = "a" -o "$2" = "b" \) -a -f test.txt ]; then echo '第一引数がaまたは第二引数がbで、かつtest.txtが存在しています' fi
if [[ ("$1" = "a" || "$2" = "b" ) && -f test.txt ]]; then echo '第一引数がaまたは第二引数がbで、かつtest.txtが存在しています' fi
var=$1 if [[ $var = 'hoge fuga' ]]; then echo success else echo fail fiv
case "$file" in *.csv) echo this is csv ;; special-* | important-*) echo this is special file ;; *) echo "Invalid file: $file" esac
for arg in "$@"; do echo $arg done
array=(aaa 'bbb ccc' ddd) for element in "${array[@]}"; do echo $element done
while [[ $# -gt 0 ]]; do echo $1 shift done
until [[ $# -eq 0 ]]; do echo $1 shift done