如何从文本文件变量到猛砸变量 [英] How to get variable from text file into Bash variable
本文介绍了如何从文本文件变量到猛砸变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题,在BASH我想一个.pid文件中读取终止进程。如何解读该文件到一个变量。我发现所有的例子都试图在许多行阅读。我只是想读一个文件只包含的PID
#!/ bin / sh的
PIDFILE =/ var / run中/ app_to_kill.pid
CurPID =(小于$ PIDFILE)杀-9 $ CurPID
解决方案
您就大功告成了!
CurPID = $(小于$ PIDFILE)
在你给的例子,你甚至不需要临时变量。只要做到:
杀-9 $(小于$ PIDFILE)
Simple question, in BASH I'm trying to read in a .pid file to kill a process. How do I read that file into a variable. All the examples I have found are trying to read in many lines. I only want to read the one file that just contains the PID
#!/bin/sh
PIDFile="/var/run/app_to_kill.pid"
CurPID=(<$PIDFile)
kill -9 $CurPID
解决方案
You're almost there:
CurPID=$(<"$PIDFile")
In the example you gave, you don't even need the temp variable. Just do:
kill -9 $(<"$PIDFile")
这篇关于如何从文本文件变量到猛砸变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文