# This is a shell script that will demonstrate basic variable # substitution. We will be ahead of the lecture a fair amount, but # the things we will do are not hard. I hope you remember pipes from # the first week (we also used those in the second week, they are # written as ‹program1 | program2›). # Let's also ask the shell to tell us what is going on. We saw this # last week: set -x # There are two types of variables that we are interested in. First # are «shell» variables, the second are «environment» variables. # There is a fair amount of overlap, which can be confusing. We need # to be careful about the distinction. variable=value # The above syntax sets the value of VARIABLE to be value. In a # traditional shell, there are no types: everything is a string. # There must be no spaces around the ‹=› ‘assignment operator’. # To use a variable, we need to use special syntax. Compare echo variable echo $variable # You can also set a variable to the output of a program. # Incidentally, the ‹$(command)› construct can be used in other # places too, we may encounter that later. variable=$(echo hello from echo) : $variable # The command ‹:› does nothing. It is useful when we are using ‹set # -x› because it shows up in the trace, along with all the arguments # (which are ‹$›-expanded). # You should run this script now. The invocation is: # # $ sh variables.sh : "That's it for now. Continue to: env.sh"