#!/bin/sh # file: simple_fork_shell_script # author: T. P. Baker # last modified by: $Author$ on $Date$ # Demonstrates use of shell command language. # To read about the features used here, use "man sh" and "man test". echo the process number of this shell is $$ if [ $# -eq 0 ]; then echo command has no parameters else echo command has $# parameters echo the parameters are: $@ fi if [ \( $# -eq 1 \) -a \( "$1" = "dofork" \) ]; then echo doing recursive call of this script, in background ./simple_fork_shell_script child& echo waiting for child $! wait $! elif [ \( $# -eq 1 \) -a \( "$1" = "child" \) ]; then echo child is about to sleep for one second sleep 1 echo child is done sleeping fi if [ \( $# -eq 1 \) -a \( "$1" = "comments" \) ]; then cat - > tmpfile <./simple_fork1_shell_script dofork # the process number of this shell is 7191 # command has 1 parameters # the parameters are: dofork # doing recursive call of this script, in background # waiting for child 7192 # the process number of this shell is 7192 # command has 1 parameters # the parameters are: child # child is about to sleep for one second # child is done sleeping # Does the script work similarly on Solaris? EOF cat tmpfile rm tmpfile fi # If the shell script is called with parameter "comments" # it outputs the above block of comments.