Techniques for Increasing Portability

There are two common techniques to increase the portability of a shell script between different versions of UNIX:

  • Conditional execution

  • 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 that sets several variables indicating the set of commands to use on a particular platform. This section looks at two common cases in which conditional execution is used:

  • Determining the remote shell command

  • Determining the proper method of using the ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.