1. 变量与替换 #!/bin/bash # 变量替换 # 另外, 变量替换还有许多别的语法 # 例如, b=${a/23/bb} 将 23 替换成 bb 等等, 用到时再找 a=375 hello=$a # 注意空格 # 如果变量中有空格, 那么变量就需要被双引号括起来 hello="a b c d" echo $hello # 输出 a b c d echo ${hello} # 输出 a b c d echo "$hello" # 输出 a b c d # -…
写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun ech…
shellscript 是linux下强大的系统管理工具,可以通过bash命令和管道命令直接在linux系统上进行编程,所写的脚本不需要编译就可以执行,对于系统管理而言十分方便. #!/bin/bash //指定所需要使用的bash(不写貌似也能运行) #program # this is my first program about shell # data 2015 5 7 cxz PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/…
写在前面:案例.常用.归类.解释说明.(By Jim) 使用多条命令shell脚本的关键是可以输入多条命令,甚至可以将一条命令的结果传递给另一条命令.date;who(两个命令shell脚本的写法) 创建shell脚本1.将shell命令放置到一个文本文件中2.指明所使用的shell,比如#!/bin/bash3.可以用#注释,但是一般注释不会被读取,第一行除外案例#!/bin/bash#This script displays the date and who's logged ondatew…
写在前面:案例.常用.归类.解释说明.(By Jim) Ctrl+C组合键可以生产SIGINT信号Ctrl+Z组合键生产SIGTSTP信号,停止进程后程序仍然留在内存中,能够从停止的地方继续运行. 捕获信号 #!/bin/bash# testing output in a background job trap "echo Haha" SIGINT SIGTERMecho "This is a test program"count=1while [ $count -…