ardggy's blog

Esc - Meta - Alt - Ctrl - Shift

getopts とやかましいモード

bashgetopts で、同一のオプションが指定されたときの振る舞いを確かめた。 たとえば rsync みたいに -v が重ねられるようだ。

#!/bin/bash

VERBOSE=""

while getopt v option; do
  case $option in
     v) VERBOSE="v${VERBOSE}" ;;
  esac
done

shift $(( OPTIND - 1 ))

echo verbose: ${VERBOSE}

テスト。

$ bash test.sh
verbose:

$ bash test.sh -v
verbose: v

$ bash test.sh -vv
verbose: vv