Sams Teach Yourself Shell Programming (Yahoo web space) in 24 Hours

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Techniques for Increasing Portability Conditional Execution Abstraction Shell scripts that run on multiple versions of UNIX often include code that is version-specific. For example, you might need to use a different command on Linux than Solaris to obtain some system information. There are two common techniques to increase the portability of a shell script between different versions of UNIX: l Conditional execution l Abstraction Conditional execution alters the execution of a script based on the system type, whereas abstraction retains the same basic flow of the script by placing the conditional statements within functions. Conditional Execution A script that uses conditional execution for portability contains an if statement at the beginning. The if statement sets several variables indicating the set of commands to use on a particular platform. In this section, you look at two common cases of conditional execution: l Determining the remote shell command l Determining the proper method of using the echo command in prompts The first case illustrates setting a variable based on the operating system type. The second case illustrates setting variables based on the behavior of a command ( echo) on a particular system. Executing Remote Commands A common use of conditional execution is in scripts that need to execute commands on remote systems. On most versions of UNIX, you can use the rsh (remote shell) command to execute commands on a remote system. Unfortunately, you cannot use this command on all versions of UNIX. On HP-UX, rsh is available, but it is not the remote shell program–it is the restricted shell program. On HPUX, you need to use the command remsh to execute commands on a remote system.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply