linux sh 读取文件内容,if判读语句,变量var打印

 

#!/bin/bash
#1 读取文件 并显示
cat state.txt | while read line
do 
    echo $line
done

#2 读取文件 并显示
cat state.txt | while read line; do echo $line; done

#3 读取一个文件内容到一个变量中
var=$(cat state.txt)
echo $var
#4 根据变量进行判读
if [ $var==0 ]; then
    echo "no run"
elif [ $var==1 ]; then
    echo "run"
else 
    echo "error"
fi

 

运行python的时候将程序PID写入文件,以方便kill程序。

import os  
  
def writePid():  
    pid = str(os.getpid())  
    f = open('athena.pid', 'w')  
    f.write(pid)  
    f.close()  

 

sh 字符串匹配

https://blog.csdn.net/xy913741894/article/details/74355576

 

posted on 2018-07-21 10:48  Maddock  阅读(527)  评论(0编辑  收藏  举报

导航