Bash:以“-"开头的回显字符串; [英] Bash: echo string that starts with "-"

查看:17
本文介绍了Bash:以“-"开头的回显字符串;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VAR="-e xyz"
echo $VAR

出于某种原因,这会打印 xyz.我似乎无法找到一种方法来获取以 -e 开头的字符串.

This prints xyz, for some reason. I don't seem to be able to find a way to get a string to start with -e.

这里发生了什么?

推荐答案

变量 VAR 包含 -e xyz,如果你通过 $<访问变量/code> -e 被解释为 echo 的命令行选项.请注意,$VAR 的内容不会自动包装到 "" 中.

The variable VAR contains -e xyz, if you access the variable via $ the -e is interpreted as a command-line option for echo. Note that the content of $VAR is not wrapped into "" automatically.

使用 echo "$VAR" 来解决您的问题.

Use echo "$VAR" to fix your problem.

这篇关于Bash:以“-"开头的回显字符串;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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