Sams Teach Yourself Shell Programming (Multiple domain web hosting) in 24 Hours
Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 24: Shell Programming FAQs Previous Chapter Next Chapter Sections in this Chapter: Shell and Command Questions File and Directory Questions Variable and Argument Questions Summary Previous Section Next Section Variable and Argument Questions In this section I will examine some questions related to variables and their use in shell scripts. I will also cover some questions related to command line arguments. How can I include functions and variable definitions from one file into another file? To include functions and variable definitions defined in one file into another file you need to use the . command as follows: . file Here file is the name of the file you want to include. I covered this topic in Chapter 22, “Problem Solving with Shell Scripts.” Is it possible to consider each argument to a shell script one at a time? You can do this using a for loop: for arg in “$@” do list done Here the variable arg will be set to each argument in turn. The specified list of commands, list, will be executed for each argument. You use $@ in this example for the arguments instead of $*, because $@ preserves the quoting used when the command was issued. The difference between $@ and $* was discussed in Chapter 12, “Parameters.” How can I forward all the arguments given to my script to another command? A common task for shell programmers is writing a wrapper script for command. A wrapper script might need to define a set of variables or change the environment in some way before a particular command starts executing. When writing wrapper scripts, you will need to forward all the arguments given to your script to a command. Usually the following is sufficient: command “$@”
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.