Differences between single quotes and double quotes in shell programming

Source: Internet
Author: User

The following uses a simple Shell Program Note.

Debian :~ /Learn/shell # Cat phonebook
Alice chebba 973-555-2015
Barbara Swingle 201-555-9257
Liz stachiw 212-555-2298
Susan Goldberg 201-555-7776
Susan topple 212-555-4932
Tony iannino 973-555-1295
Stromboli pizza 973-555-9478
Debian :~ /Learn/shell #

Debian :~ /Learn/shell # Cat Lu
# Look someone up in the phone book
Grep "$1" Phonebook
Debian :~ /Learn/shell #

This is the correct Lu program. The following shows the running result.

Debian :~ /Learn/shell #./Lu 'Susan t'
Susan topple 212-555-4932
Debian :~ /Learn/shell #./Lu Tony
Tony iannino 973-555-1295
Debian :~ /Learn/shell #

If Lu is written as ① grep $1 phonebook or ② grep '$ 1' phonebook, the following error will occur (Why ?).

Result 1:

Debian :~ /Learn/shell #./Lu Tony // The result is correct.
Tony iannino 973-555-1295
Debian :~ /Learn/shell #./Lu 'Susan t' // The result is incorrect.
Grep: T: no such file or directory
Phonebook: Susan Goldberg 201-555-7776
Phonebook: Susan topple 212-555-4932
Debian :~ /Learn/shell #

② Results:

Debian :~ /Learn/shell #./Lu Tony // The result is incorrect.
Debian :~ /Learn/shell #./Lu 'Susan t' // The result is also incorrect.
Debian :~ /Learn/shell #

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.