用簡單的定義 DEFINE_xxx 方式來方便 shell script 做 argument 設定,取得
使用時,只要在 script 前
. ./shflags之後就可以用 shflags 裡面所有的 function 變數。
原網站有說明和 example.
這裡就大概寫一些。以望站上的 example來看。
#!/bin/sh
. /path/to/shflags
#define option variable: var_name, default_value, var_comment, var_option_flag
DEFINE_string 'name' 'world' 'name to say hello' 'n'
#processing the arguments
FLAGS "$@" || exit $?
eval set -- "{$FLAGS_ARGV}"
# say hello
echo "Hello, ${FLAGS_name}" !
就像 comment 說的 一樣。
使用和輸出結果是..
./hello_world.sh -n charles Hello charles !
沒有留言:
張貼留言