Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
如果IP是可ping的,则执行某些操作(将bash命令转换为dash)_Bash_Dash Shell - Fatal编程技术网

如果IP是可ping的,则执行某些操作(将bash命令转换为dash)

如果IP是可ping的,则执行某些操作(将bash命令转换为dash),bash,dash-shell,Bash,Dash Shell,我有一个命令,如果可以访问某个特定的IP,那么在重新启动后应该打开一个程序。我使用Debian,所以sh链接到dash。我在系统启动后执行的代码是: sh -c "sleep 10 && if ping -c 1 stackoverflow.com &> /dev/null; then gedit; fi" 但使用此代码,gedit将在任何情况下打开 如果我在bash控制台中尝试 sleep 10 && if ping -c 1 stackover

我有一个命令,如果可以访问某个特定的IP,那么在重新启动后应该打开一个程序。我使用Debian,所以sh链接到dash。我在系统启动后执行的代码是:

sh -c "sleep 10 && if ping -c 1 stackoverflow.com &> /dev/null; then gedit; fi"
但使用此代码,gedit将在任何情况下打开

如果我在bash控制台中尝试

sleep 10 && if ping -c 1 stackoverflow.com &> /dev/null; then gedit; fi
然后它就正常工作了。那么如何将bash命令正确地转换为dash?

sh没有&>。您或者需要使用bash-c。。。或一次重定向一个描述符:

sh -c "sleep 1 && if ping -c 1 stackoverflow.com > /dev/null 2>&1; then notify-send hi; fi"