Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
如何运行cygwin';bashrc的startxwin是谁?_Bash_Cygwin_X11_Xterm - Fatal编程技术网

如何运行cygwin';bashrc的startxwin是谁?

如何运行cygwin';bashrc的startxwin是谁?,bash,cygwin,x11,xterm,Bash,Cygwin,X11,Xterm,我偶尔使用cygwin,从Windows 7启动mintty.exe,然后运行以下命令启动XWindows和xterm: /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe & 我试图通过在我的~/.bashrc结尾输入以下小节来自动创建xterm: if [ `ps -ef | grep XWin | wc -l` -lt 1 ] ; then echo "will start Xwin"

我偶尔使用cygwin,从Windows 7启动mintty.exe,然后运行以下命令启动XWindows和xterm:

/bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe &
我试图通过在我的~/.bashrc结尾输入以下小节来自动创建xterm:

if [ `ps -ef | grep XWin | wc -l` -lt 1 ] ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
    sleep 300
fi
但是,XWin未启动,并打印以下错误:

Usage: /usr/bin/grep [OPTION]... PATTERN [FILE]...
Try `/usr/bin/grep --help' for more information.
bash: [: too many arguments
您能建议一种从Windows启动xterm实例的方法吗

注:

  • 我阅读了Cygwin常见问题解答,并在谷歌上搜索答案
  • 环境:
    Windows 7
    CYGWIN_NT-6.1-WOW64 1.7.33-2(0.280/5/3)i686 CYGWIN

编辑
根据@EtanReisner和@pjh的评论,我将startxwin节更改为以下内容,这是有效的:

if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi
if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi

根据@EtanReisner和@pjh的评论,我将startxwin节更改为以下内容,这是有效的:

if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi
if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi

grep
正在抱怨那里的一些事情。这会导致
test
/
[
获取太多参数并自行抱怨。您需要找出
grep
抱怨的原因。(您可能还想看看是否有
pgrep
而不是管道。)Cygwin下Bash脚本出现问题的常见原因是Windows(CR-LF)行结尾是意外添加的(尽管我不知道这会导致此问题)。调试问题的一种方法是将
set-o xtrace
放在失败的代码之前。代码本身就是一个很好的例子。解决问题的一种方法是:
if!ps-ef | grep-q XWin;然后…
。正如@EtanReisner所写的,如果有“pgrep”,使用它会更好。