脚本中是否有一种方法可以确定用户是否选择了“Run In Terminal”?
解决方法 严格地说,您无法判断用户在单击脚本后是否选择了“Run In Terminal”,或者启动终端并从那里运行脚本.但是下面的命令可以帮助你,特别是[-t 2].if [ -t 1 ]; then echo "Standard output is a terminal." echo "This means a terminal is available,and the user dID not redirect the script's output."fi
if [ -t 2 ]; then echo "Standard error is a terminal." >&2 echo "If you're going to display things for the user's attention,standard error is normally the way to go." >&2fi
if tty >/dev/null; then echo "Standard input is a terminal." >$(tty) echo "The tty command returns the name of the terminal device." >$(tty)fi
echo "This message is going to the terminal if there is one." >/dev/ttyecho "/dev/tty is a sort of alias for the active terminal." >/dev/ttyif [ $? -ne 0 ]; then : # Well,there wasn't one.fi
if [ -n "$disPLAY" ]; then xmessage "A GUI is available."fi总结
以上是内存溢出为你收集整理的linux – 如何判断用户是否选择“Run In Terminal”全部内容,希望文章能够帮你解决linux – 如何判断用户是否选择“Run In Terminal”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)