Search code examples
linuxbashecho

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?

enter image description here


Solution

  • That code looks more like 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, . has no special meaning, so it will be echoed literally. The echo command puts a space between each argument, so the output will be

    Tomorrow .  will be January  . 3 . rd