#!/bin/sh
addText="cd /home/test"
AddCmd(){
#判断 file.sh 文件中是否存在该字符串
if ! grep "$addText" file.sh >/dev/null
then
#不存在,添加字符串
echo "input file"
sed '$a/'"$addText"'' file.sh > newfile
mv newfile file.sh
else
#存在,不做处理
echo "not input file"
fi
}
#执行该函数
AddCmd
shell脚本查找字符串,不存在则添加
最新推荐文章于 2024-05-15 16:35:52 发布