Command Line Quoting

Hands-On Lab

 

Photo of Michael Christian

Michael Christian

Course Development Director in Content

Length

00:30:00

Difficulty

Beginner

In this hands-on lab we'll practice quoting and escaping special characters in Linux. Quoting and escaping strings can be frustrating, but developing an understanding of when to use single quotes, double quotes, and escape characters is necessary when working with Linux.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Command Line Quoting

Introduction

In this hands-on lab we'll practice quoting and escaping special characters in Linux.

Connecting to the Lab

  1. Open your terminal application, and run the following command (remember to replace <PUBLIC_IP> with the public IP you were provided on the lab instructions page):
    ssh cloud_user@<PUBLIC_IP>
  2. Enter yes at the prompt.
  3. Enter your cloud_user password at the prompt.

Set variable1

  1. Determine the current working directory.
    pwd
  2. Set variable1 to This is 'just' a "test"..
    variable1="This is 'just' a "test"."
  3. Verify that this was successful.
    echo -e $variable1
  4. Output variable1 to a new file named value.txt.
    echo -e $variable1 > value.txt
  5. Verify that this was successful.
    cat value.txt

Set variable2

  1. Set variable2 to This is a backslash "" and this is a single quote '..
    variable2="This is a backslash "\" and this is a single quote '."
  2. Verify that this was successful.
    echo -e $variable2
  3. Append variable2 to the value.txt file.
    echo -e $variable2 >> value.txt

Set variable3

  1. Set variable3 to 3 double quotes """, and 3 single quotes ''', and three backslashes \..
    variable3="3 double quotes """, and 3 single quotes ''', and 3 backslashes \\\\."
  2. Verify that this was successful.
    echo -e $variable3
  3. Append variable3 to the value.txt file.
    echo -e $variable3 >> value.txt

Set variable4

  1. Set variable4 to This is what a newline character looks like n, it will create a new line..
    variable4="This is what a newline character looks like \n, it will create a new line."
  2. Verify that this was successful.
    echo -e $variable4 
  3. Append variable4 to the value.txt file.
    echo -e $variable4 >> value.txt
  4. List the contents of value.txt.
    cat value.txt

Conclusion

Congratulations, you've successfully completed this hands-on lab!