Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.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
Linux “第一”;如果是“那么”;声明获胜';t将stdout重定向到Mint上的/dev/null_Linux_Bash_If Statement_Stdout_Linux Mint - Fatal编程技术网

Linux “第一”;如果是“那么”;声明获胜';t将stdout重定向到Mint上的/dev/null

Linux “第一”;如果是“那么”;声明获胜';t将stdout重定向到Mint上的/dev/null,linux,bash,if-statement,stdout,linux-mint,Linux,Bash,If Statement,Stdout,Linux Mint,这是一个非常奇怪的错误。我已经在两个GNU/Linux安装上测试了它,即ArchLinux和LinuxMint17.1。我正在编写一个bash脚本,它以if语句开始 if which apt-get &> /dev/null; then x="foo" elif which yum &> /dev/null; then x="bar" elif which pacman &> /dev/null; then x="baz" 它在我的Arch安装(使用b

这是一个非常奇怪的错误。我已经在两个GNU/Linux安装上测试了它,即ArchLinux和LinuxMint17.1。我正在编写一个bash脚本,它以if语句开始

if which apt-get &> /dev/null; then x="foo"
elif which yum &> /dev/null; then x="bar"
elif which pacman &> /dev/null; then x="baz"
它在我的Arch安装(使用bash v4.3.33)上运行良好,但在我的Mint安装(bash v4.3.11)上,它完成了if语句,没有发生任何事件,但是在if语句之后,会提示用户输入,bash会立即从stdout打印(尽管我相当确定已将其重定向到/dev/null)。它看起来像:

Choose an option: /usr/bin/apt-get
其中“选择选项:”是我的提示。这不会发生在Arch上,当我把订单转到

if which pacman &> /dev/null; then x="foo"
elif which apt-get &> /dev/null; then x="bar"
提示后的尾随输出停止出现


有什么我遗漏的吗?

好了,伙计们,我知道发生了什么;这对我来说只是一个愚蠢的错误,但我真的很感谢dg99和格伦·杰克曼的帮助


我注意到,如果在图形文件管理器(Nemo)中执行,并选择“在终端中运行”,则不会出现奇怪的输出。这促使通过终端进行一些测试,我发现如果我使用
/script
而不是
sh script
执行脚本,问题就会自行解决。我真的不知道为什么会这样,但它很清楚地解决了这个问题

哪个
在这两个系统上做相同的事情?它有时被别名为更复杂的命令。尝试在两个系统上键入
which
。将脚本中的
which
更改为
type-P
,这是一个bash内置命令。
type which
命令在两个系统上显示
which is/usr/bin/which
。我将
更改为
type-P
,输出继续做同样的事情,但不是说
/usr/bin/apt-get
而是说
/path/to/script:20:/path/to/script-P::not found
如果它真的是Bash脚本,
sh脚本
是错误的(而
Bash脚本
是正确的).这是有道理的,但出于某种原因,我一直使用
sh脚本
。从现在起,我将开始使用
bash
(因为它的标题中有
#!/bin/bash
)。谢谢