Output command to null

核能气质少年 提交于 2021-01-29 11:27:19

问题


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

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

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

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?


回答1:


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

Suppress the group error message

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


来源:https://stackoverflow.com/questions/64427779/output-command-to-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!