shell笔记
var=helloworld 全局变量
local var=helloworld 局部变量
result=`ls -l`
echo $((2 + (5*2)))
$? 命令执行成功或失败 0为成功 非0为失败
$0、$1、$2...
exit 1 运行到此行退出 非0退出
my_info (){
lscpu >> log
uname –a >> log
free –h >> log
}
函数参数和脚本参数类似 $0、$1、$2...
跨脚本调用函数 source xx.sh
等于: $test 3 -eq 3; echo $?
不等于: $test 3 -ne 1; echo $?
大于等于: $test 5 -ge 2; echo $?
小于等于: $test 3 -le 1; echo $?
#!/bin/bash
var = `whoami`
if [ $var = "root" ]
then
echo "You are root"
echo "You are my God."
fi
#!/bin/bash
now=`date +'%Y%m%d%H%M'`
deadline=`date --date='1 hour' +'%Y%m%d%H%M'`
while [ $now -lt $deadline ]
do
date
echo "not yet"
sleep 10
now=`date +'%Y%m%d%H%M'`
done
echo "now, deadline reached"
#!/bin/bash
for var in `ls log*`
do
rm $var
done
网友评论