Bash Quotes


--------------------------------------------------------------------------------------------------------
Types of Quotes
--------------------------------------------------------------------------------------------------------

  • Double Quotes(""): Print value of string
  • Single Quotes(' '): Print the same value
  • Back slash(\): back Slash
  • back quotes(``): To execute any command


--------------------------------------------------------------------------------------------------------
Basic Examples
--------------------------------------------------------------------------------------------------------
[haritaraka12078@cxln4 ~]$ echo "welcome to india"
welcome to india


[haritaraka12078@cxln4 ~]$ echo "the current date is: 'date'"
the current date is: 'date'


[haritaraka12078@cxln4 ~]$ echo "the current date is: `date`"
the current date is: Fri Jun 10 06:50:45 UTC 2022


[haritaraka12078@cxln4 ~]$ echo "the current date is: `ls`"
the current date is: abc3
cloudxlab_jupyter_notebooks
combo
dir1
erro-log
exm2.txt
exm.txt



[haritaraka12078@cxln4 ~]$ echo "the current date is: `pwd`"
the current date is: /home/haritaraka12078


[haritaraka12078@cxln4 ~]$ echo "the current date is: `cal`"
the current date is:       June 2022
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30



--------------------------------------------------------------------------------------------------------
Bash Script Example 1:
--------------------------------------------------------------------------------------------------------
[haritaraka12078@cxln4 ~]$ cat quote.sh
#!/bin/bash

# String in single quote
echo 'Hello User'
echo
# String in double quote
echo "we are javatpoint"


#!/bin/bash

#quote with variable
name="You are welcome at javatpoint"

echo "$name"
echo '$name'


[haritaraka12078@cxln4 ~]$ ./quote.sh
Hello User

we are javatpoint
You are welcome at javatpoint
$name



--------------------------------------------------------------------------------------------------------
Bash Script Example 2:
--------------------------------------------------------------------------------------------------------

[haritaraka12078@cxln4 ~]$ cat example.sh
#!/bin/bash
echo
echo "When single quote is used with string:"
invitation='Welcome to javatpoint'
echo $invitation
echo
echo "When double quote is used with string:"
invitation="Welcome to javatpoint"
echo $invitation
echo
echo "When variable is used with double quote:"
Remark="Hello User!, $invitation"
echo $Remark
echo
echo "When variable is used with single quote:"
Remark='Hello User!, $invitation'
echo $Remark
echo



[haritaraka12078@cxln4 ~]$ ./example.sh

When single quote is used with string:
Welcome to javatpoint

When double quote is used with string:
Welcome to javatpoint

When variable is used with double quote:
Hello User!, Welcome to javatpoint

When variable is used with single quote:
Hello User!, $invitation