获取bash脚本以打开终端

时间:2019-06-20 12:29:57

标签: linux bash terminal

在Windows中,当我双击“批处理”脚本时,它将自动打开一个终端窗口并显示正在发生的事情。如果我要在Linux中双击bash脚本,则不会打开终端窗口来显示正在发生的事情。它在后台运行。我已经看到一个人可以在x-terminal-emulator -e "./script.sh"的新终端窗口中使用一个脚本来启动另一个脚本,但是我可以在同一个script.sh中放入任何bash命令,以便将其打开终端并告诉我发生了什么事(或者是否需要回答是/否问题)?

1 个答案:

答案 0 :(得分:1)

您可以执行类似于Slax的操作 开发人员在他们的bootinst.sh中所做的事情:

#!/usr/bin/env sh
#
#     If you see this file in a text editor instead of getting it executed,
#     then it is missing executable permissions (chmod). You can try to set
#     exec permissions for this file by using:  chmod a+x bootinst.sh
#
#     Scrolling down will reveal the actual code of this script.
#



# if we're running this from X, re-run the script in konsole or xterm
if [ "$DISPLAY" != "" ]; then
   if [ "$1" != "--rex" -a "$2" != "--rex" ]; then
      konsole --nofork -e /bin/sh $0 --rex 2>/dev/null || xterm -e /bin/sh $0 --rex 2>/dev/null || /bin/sh $0 --rex 2>/dev/null
      exit
   fi
fi

# put contents of your script here
echo hi

# do not close the terminal immediately, let user look at the results
echo "Press Enter..."
read junk

以图形方式启动时,此脚本都将正确运行 环境和tty。它尝试重新启动内部脚本 konsolexterm,但是如果都找不到它们 只会在后台运行。