Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
在fish shell提示符中测试RETVAL?_Shell_Fish - Fatal编程技术网

在fish shell提示符中测试RETVAL?

在fish shell提示符中测试RETVAL?,shell,fish,Shell,Fish,我正在尝试将我的bashrc配置转换为fish shell配置,提示中有以下部分: function fish_prompt .... if [ $RETVAL -ne 0 ] printf "✘" else printf "✓" end .... end 此配置导致错误: test: Missing argument at index 2 谁能给我解释一下,这里怎么了?RETVAL未设置: $ set -e RETVAL $ if [ $RETVAL

我正在尝试将我的bashrc配置转换为fish shell配置,提示中有以下部分:

function fish_prompt
  ....

  if [ $RETVAL -ne 0 ]
    printf "✘"
  else
    printf "✓"
  end
  ....
end
此配置导致错误:

test: Missing argument at index 2

谁能给我解释一下,这里怎么了?

RETVAL
未设置:

$ set -e RETVAL
$ if [ $RETVAL -ne 0 ]; echo foo; end
test: Missing argument at index 2
$ set RETVAL 1
$ if [ $RETVAL -ne 0 ]; echo foo; end
foo
如果要抑制错误消息,请测试变量是否存在。另外,使用fish的内置
test
,而不是外部
[

$ set -e RETVAL
$ if begin; set -q RETVAL; and test $RETVAL -ne 0; end; echo foo; else; echo bar; end
bar
$ set RETVAL 1
$ if begin; set -q RETVAL; and test $RETVAL -ne 0; end; echo foo; else; echo bar; end
foo
实际上,这可能更整洁:

if test -n "$RETVAL" -a "$RETVAL" -ne 0; echo foo; end

请注意,
[
是fish 2.1.0中的内置代码。