简体   繁体   中英

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.

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.

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.

For your second question, a better way would be (if you have sudo permissions):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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