我试过打印"狗是最棒的".用这个bash脚本.
#!/bin/bash
ANIMAL="Dog"
echo "$ANIMALs are the best."
exit
Run Code Online (Sandbox Code Playgroud)
但是,我得到了"最好的".打印出来,因为sin $ANIMALS没有与变量分开.我该如何分开?
koj*_*iro 35
带括号: echo "${ANIMAL}s are the best."
报价: echo "$ANIMAL"'s are the best.'
使用printf: printf '%ss are the best.\n' "$ANIMAL"
我大部分时间都不会使用引号.我觉得它不易读,但要注意这一点很好.
用大括号括起变量的名称.
#!/bin/bash
ANIMAL="Dog"
echo "${ANIMAL}s are the best."
exit
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6555 次 |
| 最近记录: |