Quoting

Assignment 5 Answers

  1. Add single quotes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo 'the value of $x is:' $x
    the value of $x is: 10
    
  2. Add double quotes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo "the value of \$x is: $x"
    the value of $x is: 10
    
  3. Add backslashes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo the value of \$x is: $x
    the value of $x is: 10
    
  4. Add single quotes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo 'Some special characters are: $ % & \ *'
    Some special characters are: $ % & \ * 
    
  5. Add double quotes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo "Some special characters are: \$ % & \\ *"
    Some special characters are: $ % & \ * 
    
  6. Add backslashes to the following line so that it displays as shown. If other quoting is neccessary, you may add it, too.
    $ echo Some special characters are: \$ \% \& \\ \* 
    Some special characters are: $ % & \ * 
    
  7. Add backslashes to quotes to the following line so that it displays as expected. The double quotes and the first dollar sign should be displayed. $total is a variable whos value should be displayed.
    $ echo The \"total\" sale is \$$total.
    The "total" sale is $9.95.
    
  8. Add double quotes to the following line so that it displays as expected. The double quotes and the first dollar sign should be displayed. $total is a variable whos value should be displayed.
    $ echo "The \"total\" sale is \$$total."
    The "total" sale is $9.95.
    
  9. Add single quotes to the following line so that it displays as expected. The double quotes and the first dollar sign should be displayed. $total is a variable whos value should be displayed.
    $ echo 'The "total" sale is $'$total.
    The "total" sale is $9.95.
    
  10. Break the following command onto two lines between the words "is" and "too".
    $ echo This line is \
    > too long.
    
  11. Break the following command onto two lines between the words "is" and "too".
    $ echo "This line is \
    > too long."
    
  12. Use command substitution to achive the desired output. The file name is names.
    $ echo There are $(cat names | wc -l) lines in the file.
    There are 14230 lines in the file.
    
  13. Bonus:

  14. Use command substitution to achive the disired output. Get the information from the file names.
    $ echo The most common name is \
    > $(cut -f1 -d' ' names | sort | uniq -c | \
    > sort -nr | head -1| cut -c8-).
    The most common name is JAMES.
    
    (The line breaks are not neccessary. They are only inserted so the text will fit in the box on smaller screens.)