一、case用法
新建脚本: touch test.sh,并添加如下内容:
#!/bin/sh
build_rkt(){
echo "------start build rkt------"
make rkt-dirclean
make rkt
}
build_vio(){
echo "------start build vio------"
make vio-dirclean
make vio
}
case "$1" in
rkt)
echo "case rkt"
build_rkt
;;
vio)
echo "case vio"
build_vio
;;
esac
简化脚本:
#!/bin/sh
build_module(){
echo "start build $1"
pkgname="$1-dirclean"
make "$pkgname"
make "$1"
}
echo "case $1"
build_module $1
保存后赋予权限:chmod 777 test.sh
执行脚本:./test.sh rkt 或者./test.sh vio
二、变量赋值及写入当前日期
version_num=current_dir/version_num.txt
touch $version_num
chmod 777 $version_num
time=$(date +%Y-%m-%d.%H:%M:%S) #定义日期格式
echo $time > $version_num #写入日期