脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash echo '##### Number of *.conf : ' find /etc -name *.conf | grep system | wc -l echo '##### *user.conf : ' find /etc -name *user.conf echo '##### *user.conf - xargs :…
示例脚本及注释 #!/bin/bash echo '##### Number of *.conf : ' find /etc -name *.conf | grep system | wc -l echo '##### *user.conf : ' find /etc -name *user.conf echo '##### *user.conf - xargs : ' find /etc -name *user.conf | xargs # find /etc -name *user.conf…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 1 - arguments #!/bin/bash if [ -n "$1" ];then # 验证参数是否传入 echo "The first parameter is ${1}." else echo "No arguments!" fi echo '$0 当前shell脚本的名称:' $0 ech…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash echo "No code, just some comments." # ### 通配符 # * 代表任意(0个或多个)字符 # ? 代表任意1个字符 # [abc] 匹配括号中任意一个字符 # [!abc] 不匹配括号中任意一个字符,等价于[^abc] # [a-z] 匹配括号中字符范围内的任意一个字符 # {a,…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash v1=test-variable_123 # 全局变量 v2=12345 v3='This is a test!' # 赋值语句使用单引号或双引号可以包含空格 v4="Test again!" testfun() { local v5=67890 # 局部变量 echo "局部变量:" $v5 }…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var if test $var # test - check file types and compare values then if [ $var == "right" ];then # "[]"是调用test命令的一种形式,"[]&qu…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash function Check() # 使用function定义函数 { Say # 通过函数名直接调用函数 if test $1 then return 0 # 使用return语句返回值: else echo "Command not implemented for that parameter!" exit 2 #…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash echo -e "\033[32m" # 设置输出属性,绿色字体 echo "This is a test!" echo -e "\033[0m" # 设置输出属性,恢复默认值 echo -e "\033[31m Hello Color! \033[0m" #…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash echo "hello shell!" # 打印字符串"hello shell!" echo "Date: " `date` # 显示命令执行结果 echo "\"It is a test!\"" # \ 转义字符 echo '\"…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash str="Shell" str2="Hello $str !" str3="Hello ${str} !" echo "拼接字符串: $str2" echo "拼接字符串: $str3" test1="一二三四五六七八九零&quo…