Suppose we want to use the name of (Tomcat web server)

Suppose we want to use the name of the current month in a shell script. The system provides a datecommand, which contains the month as a string, but we need to separate it from the other fields. We this using a combination of the setcommand and the $(…)construct to execute the datecom- mand and return the result (which we ll look at in more detail very soon). The datecommand outputhas the month string as its second parameter: #!/bin/shecho the date is $(date) set $(date) echo The month is $2exit 0This program sets the parameter list to the datecommand s output and then uses the positional param- eter $2to get at the month. Notice that we used the datecommand as a simple example to show how to extract positional parameters. Since the datecommand is sensitive to the language local, in reality we would have extracted the name month using date +%B. The datecommand has many other formatting options; see the manual more details. We can also use the setcommand to control the way the shell executes by passing it parameters. Themost commonly used form of the command is set -x, which makes a script display a trace of executing command. We discuss setand more of its options when we look at debugging, lateron in the chapter. shiftThe shiftcommand moves all the parameter variables down by one, so that $2becomes $1, $3becomes$2, and so on. The previous value of $1is discarded, while $0remains unchanged. If a numerical parame- ter is specified in the call to shift, the parameters will move that many spaces. The other variables $@, and $#are also modified in line with the new arrangement of parameter variables. shiftis often useful for scanning through parameters, and if your script requires 10 or more parameters, you ll need shiftto access the tenth and beyond. Just as an example, we can scan through all the positional parameters like this: #!/bin/shwhile [ $1 != ]; doecho $1 shiftdoneexit 059ShellProgrammingb544977
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

WordPress database error: [Table 'armadillowebhosting_com_-_apache.wp_comments' doesn't exist]
SELECT * FROM wp_comments WHERE comment_post_ID = '85' AND comment_approved = '1' ORDER BY comment_date

Leave a Reply