Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 获取bash脚本以打开终端_Linux_Bash_Terminal - Fatal编程技术网

Linux 获取bash脚本以打开终端

Linux 获取bash脚本以打开终端,linux,bash,terminal,Linux,Bash,Terminal,在Windows中,当我双击一个批处理脚本时,它将自动打开一个终端窗口,并显示正在发生的事情。如果我在Linux中双击一个bash脚本,终端窗口不会打开来显示发生了什么;它在后台运行。我已经看到,可以使用一个脚本在一个新的终端窗口中启动另一个脚本,使用x-terminal-emulator-e./script.sh“,但是是否有任何bash命令可以放入相同的(一个)script.sh,这样它就可以打开一个终端并显示正在发生的事情(或者如果我需要回答y/n问题)?你可以做类似的事情 开发人员在其b

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

你可以做类似的事情 开发人员在其
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中的环境和功能。它尝试重新启动内部的脚本
konsole
xterm
但如果两者都找不到,则
将只在后台运行。

我不知道这是否可行,但可能
如果![-t0];然后执行x-terminal-emulator-e“/script.sh”;fi
?@Edward:你说的“在Linux中双击”是什么意思?双击哪里(即打开哪个应用程序向您显示脚本),使用哪个窗口管理器?呵呵,或者
#/usr/bin/x-terminal-emulator-ebash script.sh
作为脚本的第一行。这可能是一个可怕的黑客行为。@user1934428任何地方,比如桌面、Nautilus或totalcommander类型的管理器。@Edward:对于窗口管理器,我指的是KDE或Gnome之类的东西。如果我理解正确,你需要一个操作,上面写着:“用程序XXX打开这个文件”,你的XXX恰好是你选择的终端程序。