[shell]简单的shell提示和参数脚本

 该shell脚本有如下点:

  • bash or dash
  • case语句的写法
  • 脚本help写法
  • 参数是否为空的写法
  • 算数运算的写法
#! /bin/bash
case "$1" in
    -h|--help|?)
    echo "Usage: 1st arg:pin name, 2st arg:reset time"
    echo "1st arg pin name:lte-reset,zigbee-reset"
    echo "2st arg reset time in ms"
    exit 0 
;;
esac

if [ ! -n "$1" ]; then
    echo "pls input 1st arg"
    exit
fi


if [ ! -n "$2" ]; then
    echo "pls input 2st arg"
    exit
fi

echo 0 > /home/gpio/$1
time=$[ $2 * 1000 ] 
echo $time > /home/gpio/$1

echo "you reset $1 with $2ms"

 

下面的脚本:

  • 多条case分支
  • 字符串比较
#! /bin/bash

USRPWM_DIR="/home/pwm"

case "$1" in
    -h|--help|?)
    echo "Usage1:1st arg:disable, enable"
    echo "Usage2:1st arg:period in us, 2st arg duty in us"
    exit
;;
    enable|disable)
    if [ "$1" == "enable" ] ; then
    echo "enable power charge"
        echo 1 > $USRPWM_DIR/power-charge/enable
    exit
    else
     echo "disable power charge"
        echo 0 > $USRPWM_DIR/power-charge/enable
    exit
    fi 
;;
esac

if [ ! -n "$1" ] ; then
    echo "pls input 1st arg: period with us"
    exit
fi
if [ ! -n "$2" ] ; then
    echo "pls input 2st arg: duty with us"
    exit
fi

arg1=$[ $1 * 1000 ]
arg2=$[ $2 * 1000 ]

echo $arg1 > $USRPWM_DIR/power-charge/period
echo $arg2 > $USRPWM_DIR/power-charge/duty_cycle
echo 1 > $USRPWM_DIR/power-charge/enable

 

转载于:https://www.cnblogs.com/aaronLinux/p/6893589.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值