首页 > 代码库 > Bash Excercises
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
Bash Excercises
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。