我们如何在Shell脚本中将变量与字母分开? [英] How do we separate variables from letters in shell scripting?
本文介绍了我们如何在Shell脚本中将变量与字母分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试打印狗是最好的".这个bash脚本.
I tried printing "Dogs are the best." with this bash script.
#!/bin/bash
ANIMAL="Dog"
echo "$ANIMALs are the best."
exit
但是,我得到了最好的".而是打印出来,因为$ANIMALS
中的s
没有与变量分开.如何将其分开?
However, I got " are the best." printed out instead because the s
in $ANIMALS
is not separated from the variable. How do I separate it?
推荐答案
带大括号:echo "${ANIMAL}s are the best."
带引号:echo "$ANIMAL"'s are the best.'
使用printf:printf '%ss are the best.\n' "$ANIMAL"
我大部分时间不会使用引号.我觉得它不可读,但是请注意.
I wouldn't use the quotes one most of the time. I don't find it readable, but it's good to be aware of.
这篇关于我们如何在Shell脚本中将变量与字母分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文