如果我有脚本“script1.sh”并且我想让它打印自己的 PID 作为第一步。我怎样才能在 bash 中做到这一点?
我刚刚开始学习 bash。我有以下脚本,我想知道以下命令的作用是为了开始了解这个世界。
if [ ! -w "." ]
then
echo "You need write permission in the directory"
exit 1
fi
firefoxGeditOpen=ps -d | grep -ic -e firefox -e gedit
if [[firefoxGeditOpen>0]]
then
echo "Firefox and Gedit must be closed to let the script work"
exit 1
fi
while(true)
do
firefox &
firefoxPid=$!
gedit &
geditPid=$!
echo "Firefox PID $firefoxPid Gedit PID $geditPid">>result.txt
wait
echo "You have closed all the processes. They will be re-opened">>result.txt
done
Run Code Online (Sandbox Code Playgroud)
提前致谢!