Bash printf文字逐字字符串 [英] Bash printf literal verbatim string
本文介绍了Bash printf文字逐字字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为使代码具有可移植性,我尝试使用printf
而不是echo
.但是然后
To make my code portable, I try to use printf
rather than echo
. But then
printf "-dogs-cats"
返回错误.当前情况下的解决方法是:
returns an error. A workaround in the present case is:
printf "-";printf "dogs-cats"
但是是否有通用的可移植命令(或带有printf
的选项)将任意字符串打印为文字/普通字,而不是尝试将字符串解释为格式?
But is there a general, portable command (or an option with printf
) that will print an arbitrary string as a literal/verbatim, not try to interpret the string as a format?
我在 BSD Unix(在Mac上)中工作,但是我的目标是编写代码也可以在其他Unix版本中使用.
I work in BSD Unix (on a Mac), but my objective is code that would work in other Unix flavors as well.
推荐答案
使用格式规范:
printf '%s' "-dogs-cats"
这篇关于Bash printf文字逐字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文