gpt4 book ai didi

linux - 获取 bash 脚本以打开终端

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:58 25 4
gpt4 key购买 nike

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

最佳答案

你可以做类似于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 并且如果它没有找到它们只会在后台运行。

关于linux - 获取 bash 脚本以打开终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56686044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com