UNIX shell scripting tutorials

Bourne/bash shell scripts: if statement syntax

contributed by Rex on October 20, 2003 under Bourne shell scripting

Conditional expressions give programs life. The ability to branch makes shell scripts powerful. This recipe shows the basic if then else structure for sh, ksh, bash, zsh, etc.

 

Determine if a file is readable by current Bourne shell script user

contributed by Rex on under Bourne shell scripting

A well contructed shell script, like any good program, should handle error conditions gracefully. Checking if a file is readable before attempting to read it allows a script to branch instead of abort or display an error message.

 

Determine if a file is writable by a Bourne script user

contributed by Rex on under Bourne shell scripting

From a Bourne shell script (sh, ksh, bash, …), it is possible to test if a file exists and is writable by the user running the script.

 

Determine if file exists in a Bourne/bash shell script

contributed by Rex on under Bourne shell scripting

 

Sending multiple lines of input to a program

contributed by Rex on under UNIX shell scripting

Using a ‘here document’ it is possible to send multiple lines of input to a program from a shell script.