简体   繁体   English

是否可以检测应用程序何时以bash关闭

[英]Is it possible to detect when a application closes in bash

I need a way to figure out if an application I launch from a bash script has finished and closed so I may clean up after it. 我需要一种方法来确定我从bash脚本启动的应用程序是否已完成并关闭,以便在此之后进行清理。

Is there a way to detect this when launching the application from a script? 从脚本启动应用程序时,是否有办法检测到这一点? Is there a function that will run the application and then block the script until the called application has finished and returned? 是否有一个功能可以运行应用程序,然后阻止脚本,直到被调用的应用程序完成并返回?

The purpose for this is to unlock luks partitions, launch an application that will use the data stored on them, and then once that application returns to clean up and lock the luks partitions. 这样做的目的是解锁luks分区,启动将使用存储在其上的数据的应用程序,然后一旦该应用程序返回以清理并锁定luks分区。

Thanks. 谢谢。

Does something like this works for your first question: 这样的事情对您的第一个问题有用吗?

list=$(ls -l1)
echo "ls output: $list"

The echo command will wait until the command inside $( and ) finishes. echo命令将等待,直到$()的命令完成。

For your second question, a better way would be (if you have sudo permissions): 对于第二个问题,更好的方法是(如果您具有sudo权限):

sudo su -c 'echo "hi from $(whoami)"'
echo "hi from $(whoami)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM