【问题标题】:Is there a way to make a shell become interactive in the middle of a script?有没有办法让 shell 在脚本中间变得可交互?
【发布时间】:2010-01-29 09:04:24
【问题描述】:

我想做这样的事情:

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

bash 可以吗?如果没有,您是否看到了做同样事情的另一种方法?

【问题讨论】:

  • 非常感谢你们两位的回答!

标签: linux bash unix shell


【解决方案1】:

结构如下:

test.sh

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

环境.sh

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

在行动:

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

【讨论】:

    【解决方案2】:

    您可以在脚本中间调用另一个 shell,但更改为例如环境变量不会反映在它之外。

    【讨论】:

      猜你喜欢
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      相关资源
      最近更新 更多