DistributedNetworks DistributedNetworks


Embedded Commands   «Prev  Next»

Embedded command syntax - Exercise

Form correct embedded statements

Objective: Practice embedded command execution

Exercise scoring

This exercise is worth 5 points and is auto-scored. When you complete the exercise, click the OK, I'm Done button to receive full credit.

Instructions

  1. Log in to your UNIX account.
  2. Use back quotes to assign output to a variable, by entering the lines below.
When typing assignment statements in the shell, be careful not to include any spaces around the equal sign. You will get an error message if you do.

now=`date`
numusers=`who | wc –l `
echo $now
echo $numusers

  1. Observe the difference between single and double quotes, by trying the following two lines.

echo "today is `date`"
echo ‘today is `date`’

Do you see the difference between these 2 commands? Which is better to use with embedded command execution?
  1. Observe the behavior of carriage returns in the shell. In the first assignment statement below, the carriage returns from the cat command will be converted into spaces. In the second assignment statement, the carriage returns will be preserved. Type in the commands below to observe the difference between using and not using the double quotes around an embedded command.

names=`cat fullnames`
echo $names
names="`cat fullnames`"
echo $names