OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Parameter Expansion

We're only going to touch briefly on parameter expansion in this chapter, but we'll be covering it extensively later. It's a feature that is more useful in shell scripts than directly on the command line. Many of its capabilities have to do with the system's ability to store small chunks of data and to give each chunk a name. Many such chunks, more properly


called variables, are available for your examination. For example, the variable named “USER” contains your username. To invoke parameter expansion and reveal the contents of USER you would do this:


[me@linuxbox ~]$ echo $USER

me

[me@linuxbox ~]$ echo $USER

me


To see a list of available variables, try this:



[me@linuxbox ~]$ printenv | less

[me@linuxbox ~]$ printenv | less


You may have noticed that with other types of expansion, if you mistype a pattern, the ex- pansion will not take place and the echo command will simply display the mistyped pat- tern. With parameter expansion, if you misspell the name of a variable, the expansion will still take place, but will result in an empty string:



[me@linuxbox ~]$ echo $SUER


[me@linuxbox ~]$

[me@linuxbox ~]$ echo $SUER


[me@linuxbox ~]$


Top OS Cloud Computing at OnWorks: