简体   繁体   中英

execute another unix command from shell script

I have a shell script which goes to certain directory and delete all sub directories present under parent directory (/home/nandus/tryd). After deletion, script has to show parent directory structure post delete operation, just to show to end user that all sub directories are deleted.

I tried to use exec for rm -rf *, but its not returning to main program and its not performing remaining steps in the shell script.

Can you please let me know how to do this shell script?

  cd /home/nandus/tryd
  exec rm -rf *
  echo '/home/nandus/tryd directory structure post delete'
  cd /home/nandis/tryd
  exec pwd
  exec ls -ltr

strong text

as bash, exec replacing the current program with a new one. not forking childs.

Open a bash shell, try the following

mkdir tmp && cd tmp
exec sleep 10

After directory build and set, Bash session replaced with sleep 10 which exit automatically after 10sec

also

mkdir tmp && cd tmp
exec pwd && sleep 10

Bash session replaced with pwd, which not designed to keep session and execute the "&&", so sleep never reached.

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