The difference between a Linux shell, a double-quote "", a single quote ", and an anti-quote"

Source: Internet
Author: User



Learn a bash script today and see that there is a: bin= ' dirname '



(dirname filename is the directory where the file is exported, and $ is the file name of the bash file, which is generally used in bash to enter the directory where the script is located)



I tried the cat $bin



The output is:.



Then I'm going to take the anti-quote "' Out: Bin=dirname"



Error after running cat $bin.






I looked online for some of Bash's single-quote ', double-quote ' and ' anti-quote ' differences.



Single quote ' and double quote ' "



Both are the problem of resolving a space in the middle of a variable.



In bash, "whitespace" is a very special character, such as the str=this is String defined in bash, which will cause an error, using single quotes "and double quotes" in order to avoid errors.



The single quote ', double quote ' "is the difference between a single quote ' ' that deprives all characters of a special meaning, and a single quote ' inside a simple character. The double quotation mark "" is an exception to the argument substitution ($) and command substitution (") in the double quotation mark" ".



Say n=3.



Echo ' $n '



The result is N3.



Change it to double quotes, echo "$n," and the result is 3.






Anti-Quote "'



Anti-quote ' is command substitution, command substitution means that the shell can execute the command in the ', and the output will be saved temporarily, and output in the appropriate place. Syntax: ' Command '



In the following example, the command execution results are saved in a variable:


#!/bin/bash

DATE=`date`
echo "Date is $DATE"

USERS=`who | wc -l`
echo "Logged in user are $USERS"

UP=`date ; uptime`
echo "Uptime is $UP"


Operation Result:


Date is Thu Jul  2 03:59:57 MST 2009
Logged in user are 1
Uptime is Thu Jul  2 03:59:57 MST 2009
03:59:57 up 20 days, 14:03,  1 user,  load avg: 0.13, 0.07, 0.15


The difference between a Linux shell, a double-quote "", a single quote ", and an anti-quote"


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.