brace expansion

درخواست حذف این مطلب

brace expansion



echo {a,b}.js {a,b} same as a b {a,b}.js same as a.js b.js {1..5} same as 1 2 3 4 5

conditionals

درخواست حذف این مطلب
[ -o noclobber ] if optionname is enabled [ ! expr ] not [ x ] && [ y ] and [ x ] || [ y ] or [ -z string ] empty string [ -n string ] not empty string [ num -eq num ] equal [ num -ne num ] not equal [ num -lt num ] less than [ num -le num ] less than or equal [ num -gt num ] greater than [ num -ge num ] greater than or equal [[ string =~ string ]] regexp (( num < num )) numeric conditions

defining arrays

درخواست حذف این مطلب
defining arrays


fruits=('apple' 'banana' 'orange') fruits[0]="apple" fruits[1]="banana" fruits[2]="orange"

working with arrays

درخواست حذف این مطلب
working with arrays

echo ${fruits[0]} # element #0 echo ${fruits[@]} # all elements, space-separated echo ${#fruits[@]} # number of elements echo ${#fruits} # string length of the 1st element echo ${#fruits[3]} # string length of the nth element echo ${fruits[@]:3:2} # range (from position 3, length 2)

operations

درخواست حذف این مطلب
operations
fruits=("${fruits[@]}" "watermelon") # push fruits=( ${fruits[@]/ap*/} ) # remove by regex match unset fruits[2] # remove one item fruits=("${fruits[@]}") # duplicate fruits=("${fruits[@]}" "${veggies[@]}") # concatenate lines=(`cat "logfile"`) # read from file

case/switch

درخواست حذف این مطلب
case/switch
case "$1" in start | up) vagrant up ;; *) echo "usage: $0 {start|stop|ssh}" ;; esac

مدیریت

درخواست حذف این مطلب
:.. مطالب را از وبنمای اصلی دنبال کنید ..:
linux / gnu لینو گنو

getting options

درخواست حذف این مطلب
getting options

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in -v | --version ) echo $version exit ;; -s | --string ) shift; string=$1 ;; -f | --flag ) flag=1 ;; esac; shift; done if [[ "$1" == '--' ]]; then shift; fi