Contact us |
Understanding QuotationsTable of contents:Exercise 5Understanding QuotationsYou will often have to use quotations while writing scripts. There are three types of quotation marks. They are: The forward quote: ' The double quote: " The back quote: ` They all serve different purposes. The double quote is used mainly to hold a string of words and preserve white space. Forward quotes are used mostly with variables. If a variable is enclosed in double quotes, its value will be evaluated. If it is enclosed in forward quotes, its value will not be evaluated. Back quotes are different from double and forward quotes. They are not used in preserving white space. To demonstrate the use of double quotes1. Make sure you are still in the myscripts directory. 2. Create a single directory called “single folder1”. Type: 3. Run the ls command to view the folder you just created. Type: 4. You created two separate folders; “single” and “folder1” instead a single folder. To create a single folder use the double quotes to enclose the folder name. This will preserve the white spaces. Type; 5. Run the ls command again to see the new directory. 6. What is the command to change to the new “single folder1” directory you just created? To demonstrate the use of forward quotes1. You will create a variable on the fly called “name”. It will store the value “Anna” 2. Make sure you are still in the myscripts directory. Type; [root@localhost myscripts]# name=anna 3. Make sure the variable is set: [root@localhost myscripts]# echo "Her name is $name" Her name is anna The echo command substituted the value of the variable name with it’s value. 4. Assuming you don’t want the value of the variable evaluated. You would use forward quotes. [root@localhost myscripts]# echo ' Her name is $name ' Her name is $name To demonstrate the use of back quotes1. You will first attempt to print a message on the screen using the date command without the back quotes; [root@localhost myscripts]# echo "Today is date" Today is date 2. You will use the back quote to make sure the date command is executed. Type; [root@localhost myscripts]# echo "Today is `date`" Today is Sun Jul 28 20:41:56 PDT 1902
|
Login... |