简体   繁体   English

Bash echo 输出字符串和字符的混合

[英]Bash echo output mix of string and character

I am taking an assessment and stumbled across the following sample question, but when I run the line it's none of the options?我正在接受评估并偶然发现以下示例问题,但是当我运行该行时,它没有任何选项? Which is the correct answer?哪个是正确答案?

在此处输入图片说明

. is the string concatenation operator for PHP.是 PHP 的字符串连接运算符。 In bash, you could just do echo Tomorrow will be January ${num}rd .在 bash 中,你可以只做echo Tomorrow will be January ${num}rd

Both versions of the code output Tomorrow will be January 3rd .两个版本的代码输出Tomorrow will be January 3rd

That code looks more like PHP.该代码看起来更像 PHP。 . is the concatenation operator, and it can be used with both strings and numbers (it will convert the number to a string).是连接运算符,它可以用于字符串和数字(​​它将数字转换为字符串)。 The output will be输出将是

Tomorrow will be January 3rd

In bash , .bash. has no special meaning, so it will be echoed literally.没有什么特别的意思,所以会从字面上呼应。 The echo command puts a space between each argument, so the output will be echo命令在每个参数之间放置一个空格,因此输出将是

Tomorrow .  will be January  . 3 . rd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM