基础命令示例
#!/bin/bash 固定格式 echo "input str" 输出字符串到屏幕 read 变量名 读取键盘输入 test $first == $second && echo "dengyv" || echo "notdeng" 判断字符串是否相等 echo "file name" $0 。脚本名称 echo "total param num" $# 。参数个数 echo "whole param" $@ 。输出所有参数 echo "first param" $1 。输出第一个参数 [ "$varname" == "hello" ] 。判断字符串是否相等,注意[ ] 内部要用空格和代码隔开,$varname要加双引号
shell判断语句
read -p "y/n?:" value if [ "$value" == "Y" ] || [ "$value" == "y" ]; then echo "your input is Y" exit 0 fi if [ "$value" == "N" ] || [ "$value" == "n" ]; then echo "your input is Y" exit 0 else echo "not illegal" fi #case语句 case $1 in "a") echo "a" ;; "b") echo "b" ;; *) echo "other" ;; esac
shell脚本函数示例
#!/bin/bash
print() { echo "param 1:$1" echo "param 2:$2" } print a b #调用print函数,并传入a,b两个参数
while循环
while [ "$value" != "close" ] do read -p "your input" str echo "ok" done echo "while over"
标签:脚本,shell,基础,param,echo,value,input,your From: https://www.cnblogs.com/ddrm/p/17643672.html