LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   In BASH shell, what is the difference in usage between single and double quotes? (https://www.linuxquestions.org/questions/linux-newbie-8/in-bash-shell-what-is-the-difference-in-usage-between-single-and-double-quotes-166328/)

davidas 04-05-2004 02:26 AM

In BASH shell, what is the difference in usage between single and double quotes?
 
Eg. what's the difference between

1) alias ls='ls --color' and alias ls="ls --color"

2) find ./ -name '.bash*' and find ./ -name ".bash*"

The output seems to be similar. (?)

Under what circumstances would the difference be significant?

Thanks !

batchild 04-05-2004 02:37 AM

Hello,

Good explanation here:
http://www.injunea.demon.co.uk/pages/page206.htm

..........

Quoting and Escaping

The difference between the single and double quote are also useful to know. The single quote is what you use to enclose a literal string. Whatever is between single quotes remains unchanged by the shell. If you enclose something in double quotes then concatenated blanks are preserved (as in the literal case with the single quotes) but variables are substituted by their values and filenames are expanded from their wild-cards to full filenames and or paths. The best way to see this is in the example below.

Example quoting
my_name="Fred Smith" # Set a variable
echo "$my_name" # Will output - Fred Smith
echo '$my_name' # Will output - $my_name

............

--John Lanier

davidas 04-05-2004 03:00 AM

Thanks batchild! Exactly what I need.


Quote:

Originally posted by batchild
Hello,

Good explanation here:
http://www.injunea.demon.co.uk/pages/page206.htm

..........

Quoting and Escaping

The difference between the single and double quote are also useful to know. The single quote is what you use to enclose a literal string. Whatever is between single quotes remains unchanged by the shell. If you enclose something in double quotes then concatenated blanks are preserved (as in the literal case with the single quotes) but variables are substituted by their values and filenames are expanded from their wild-cards to full filenames and or paths. The best way to see this is in the example below.

Example quoting
my_name="Fred Smith" # Set a variable
echo "$my_name" # Will output - Fred Smith
echo '$my_name' # Will output - $my_name

............

--John Lanier



All times are GMT -5. The time now is 07:36 PM.