输出命令为空 [英] Output command to null

查看:45
本文介绍了输出命令为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure管道变量来为命令构造一组参数.我必须用于Azure管道的变量类型为宏格式(例如 $(var)),您可以在此处查看其详细信息:

I am using Azure pipelines variables to construct a set of parameters for a command. The type of variable I must use for Azure pipelines is in macro format (like $(var)), you can see the details of it here: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#runtime-expression-syntax

如果 $(var)不包含值,则不打印"nothing",而是打印 $(var)

If $(var) does not contain a value, instead of printing "nothing", it will print $(var)

当我运行命令并且未传递该值时,屏幕上会提示错误,提示未找到该命令.目前,这没什么大不了的,它不会出错我下面的命令集,但是我希望至少能抑制它.

When I run my command and that value isn't passed in, an error prompts on the screen that command was not found. At the moment it's not a big deal, it doesn't error my following set of commands, but I was hoping to suppress it at the very least.

VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)"

if [ ${#VAR_TERRAFORMDESTROY} -ge 1 ]; then
  VAR_TERRAFORMDESTROY="yes"
else
  VAR_TERRAFORMDESTROY="no"
fi

在日志输出中,它将打印/vsts/_work/_temp/4e426335-0930-4375-b05c-c4dbbcb38139.sh:第5行:TERRAFORMDESTROY:未找到命令

In the logs output it will print /vsts/_work/_temp/4e426335-0930-4375-b05c-c4dbbcb38139.sh: line 5: TERRAFORMDESTROY: command not found

我尝试了 VAR_TERRAFORMDESTROY =" $(TERRAFORMDESTROY)".>/dev/null 2>& 1 ,但是因为>/dev/null 2>& 1 不在方括号()内,它不会将结果输出为null.由于Azure YAML变量的工作原理,它不能放在方括号内.

I have tried VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)" > /dev/null 2>&1, but because > /dev/null 2>&1 is not inside the brackets (), it will not output the result to null. And it cannot be inside the brackets due to how Azure YAML variables work.

请问有人可以建议抑制我找不到的命令输出吗?

Can anyone suggest anything to suppress the command not found output for me, please?

推荐答案

请问有人可以抑制我找不到的命令吗?

Can anyone suggest anything to suppress the command not found output for me, please?

禁止显示组错误消息

{ VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)"; } > /dev/null 2>&1

这篇关于输出命令为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆