首先,您可以这样做:
#!/bin/bash
dayoffset=$1
processMode=$2
echo "Do something with $dayoffset and $processMode."
用法:
./start.sh 1 true
另一个:
#!/bin/bash
while [[ $# -gt 0 ]]; do
case "$1" in
-dayoffset)
day_offset=$2
shift
;;
-processMode)
if [[ $2 != true && $2 != false ]]; then
echo "Option argument to '-processMode' can only be 'true' or 'false'."
exit 1
fi
process_mode=$2
shift
;;
*)
echo "Invalid argument: $1"
exit 1
esac
shift
done
echo "Do something with $day_offset and $process_mode."
用法:
./start.sh -dayoffset 1 -processMode true
使用日偏移量解析示例参数:
#!/bin/bash
dayoffset=$1
date -d "now + $dayoffset days"
测试:
$bash script.sh 0
Fri Aug 15 09:44:42 UTC 2014
$bash script.sh 5
Wed Aug 20 09:44:43 UTC 2014