Bash Excercises

1. cat <<EOF

#!/bin/bash
function printHelp {
cat<<EOF

Run the Dash vector tests.
Usage:
./run_dash_vector_test.sh <vector_env> <dash_version>

The vector environment should be the value 1 or 2, to indicate which of the
static Dash vector environments should be used.

The Dash version should be a valid git revision, e.g. 'master' or
'2.3352-HOTFIX'.

EOF
}

if [[ "$#" -ne 2 ]]
then
printHelp
exit -1
fi

2. let i++
reference:
[1] http://askubuntu.com/questions/385528/how-to-increment-a-variable-in-bash

#!/bin/bash
let i=1
for SCRIPTLET in "${SCRIPTLETS[@]}"
do
echo " ${i}) ${SCRIPTLET}"
let i++
done

The same as:

#!/bin/bash
i=0
while [ "$i" -lt 10 ]
do
<command block>
i=`expr $i + 1`
done

or even

#!/bin/bash
i=0
while [ "$i" -lt 10 ]
do
<command block>
(( i = i + 1 )) # or (( i+=1 ))
done

 3. getopts

#!/bin/bash
while getopts ":d:e:g:v:" opt
do
  case $opt in
    d) DASH_REVISION="$OPTARG" ;;
    e) EMAIL="$OPTARG" ;;
    g) GIT_DIR="$OPTARG" ;;
    v) VECTOR_ENV="$OPTARG" ;;
    \?) echo "Invalid option: -$OPTARG" >&2; exit -1 ;;
  esac
done

转载于:https://www.cnblogs.com/codingforum/p/6208620.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值