问题来了,一个只包含以下内容的简单脚本secs=$((60))而 [ $secs -gt 0 ];做echo -ne "$secs\033[0K\r"睡觉 1: $((秒--))完毕现在关机工作正常,但如果我尝试将其发送到这样的新终端gnome-terminal -e "bash -c'秒=$((60))而 [ $secs -gt 0 ];做echo -ne \"$secs\033[0K\r\"睡觉 1: $((秒--))完毕立即关机'"它失败了,只是关闭了.如果我删除关闭行,我会收到此错误:选项-e"已弃用,可能会在 gnome-terminal 的更高版本中删除.使用--"终止选项并在其后执行命令行.有谁知道我该如何解决这个问题?谢谢 解决方案 最简单的方法是导出一个函数:倒计时(){秒=60而 (( 秒 > 0 ));做printf '%s\033[0K\r' "$secs"睡觉 1((秒--))完毕现在关机}导出 -f 倒计时gnome-terminal -- bash -c 倒计时I have a script to which I wanna add a shutdown timer at the end, I'd like the countdown to run in a new terminal windows so I can cancel it since the script will usually be run in the background.Here's the problem,a simple script containing only the followingsecs=$((60))while [ $secs -gt 0 ]; do echo -ne "$secs\033[0K\r" sleep 1 : $((secs--))doneshutdown nowworks fine, but if I try to send it to a new terminal like thisgnome-terminal -e "bash -c'secs=$((60))while [ $secs -gt 0 ]; do echo -ne \"$secs\033[0K\r\" sleep 1 : $((secs--))doneshutdown now'"it fails and just shuts down. If I remove the shutdown line I get this error : Option "-e" is deprecated and might be removed in a later version of gnome-terminal.Use "-- " to terminate the options and put the command line to execute after it.Does anyone know how I could fix this?thanks 解决方案 The easy way to do this is to export a function:countdown() { secs=60 while (( secs > 0 )); do printf '%s\033[0K\r' "$secs" sleep 1 ((secs--)) done shutdown now}export -f countdowngnome-terminal -- bash -c countdown 这篇关于从脚本向新终端发送一系列命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-24 12:43