Skip to content

Instantly share code, notes, and snippets.

@foowaa
Created April 26, 2019 06:28
Show Gist options
  • Save foowaa/db07b9fc8fb02f51b6d17099c96fc5bb to your computer and use it in GitHub Desktop.
Save foowaa/db07b9fc8fb02f51b6d17099c96fc5bb to your computer and use it in GitHub Desktop.
一般的 shell 脚本
#! /bin/bash
# constants definition
baseDir=$(cd `dirname "$0"`;pwd) #返回文件当路径
home=$baseDir/..
registry=abc.com
name=$registry/dev
# functions
funWithReturn(){
echo "这个函数会对输入的两个数字进行相加运算..."
echo "输入第一个数字: "
read aNum
echo "输入第二个数字: "
read anotherNum
echo "两个数字分别为 $aNum 和 $anotherNum !"
return $(($aNum+$anotherNum))
}
funWithReturn
echo "输入的两个数字之和为 $? !"
# main
[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return #无文件就返回
cd $home/alex
$baseDir/run.sh
# http://www.runoob.com/linux/linux-shell-basic-operators.html
if [ ! -d $baseDir/../tmp ]; then
mkdir $baseDir/../tmp
fi
cd $baseDir/../tmp
if [ -f $filename ]; then
rm -rf $filename
fi
# package version
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' | xargs)
# http://man.linuxde.net/curl
curl -i -X POST -H "Content-Type: multipart/form-data" \
-F "droplet=@$filename" \
-F "name=foo" \
-F "password=bar" \
http://man.linuxde.net/text.iso
zip -j $filename -r ../app
echo done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment