linux shell

有意无意写了一些shell脚本。

是时候做个小结了。

头标

# !bin/bash

  

循环

for i in {start..end}
    do xxx
done

 

条件判断

if [ xxx ]
then
    xxx
if

函数定义&参数

xxx()
{
   echo $1
   echo $2
   echo $3  
}

xxx,具体函数名。 $1,$2,$3为具体的输入参数,测试如下:

[ywt@centos]$xxx 1 2 3
1
2
3

shell脚本的进程pid的保存

echo $$ > /tmp/xxx.pid

demo

# !bin/bash
echo $$>/tmp/hello.pid
hello()
{
   echo "hi,$1"   
}

hello "tommy"
原文地址:https://www.cnblogs.com/Tommy-Yu/p/5355974.html