簡體   English   中英

有沒有辦法讓shell在腳本中間變得交互?

[英]Is there a way to make a shell become interactive in the middle of a script?

我想做點什么:

do lots of stuff to prepare a good environement
become_interactive
#wait for Ctrl-D
automatically clean up

bash有可能嗎? 如果沒有,你看到另一種做同樣事情的方法嗎?

結構如下:

test.sh

#!/bin/sh
exec bash --rcfile environ.sh

environ.sh

cleanup() {
    echo "Cleaning up"
}
trap cleanup EXIT
echo "Initializing"
PS1='>> '

在行動:

~$ ./test.sh 
Initializing
>> exit
Cleaning up

您可以在腳本中間調用另一個shell,但是對環境變量的更改不會反映在它之外。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM