System information
An Introduction to Shells in General
Axis Communications AB provides NO support for application development of any kind. The information
here is provided "as is", and there is no guarantee that any of the examples shown will work in your
particular application.
Revision 1.02 October 2002 41
• -v Echo input lines as they are read
• -x Trace
• -u Unset variables
Example
sh script #Run a shell script
Description
Sh is the shell, which forms the user’s main interface with the system. On startup, the shell reads
/etc/pro-file and $HOME/.profile, if they exist, and executes any commands they
contain. The Minix shell has most of the features of the V7 (Bourne) shell, including redirection
of input and output, pipes, magic characters, background processes, and shell scripts. A brief
summary follows, but whole books have been written on shell programming alone.
Some of the more common notations are:
date
# Regular command
sort <file
# Redirect stdin (standard input)
sort <file1 >file2
# Redirect stdin and stdout
cc file.c 2>error
# Redirect stderr
a.out >f 2>&1
# Combine standard output and standard error
sort <file1 >>file2
# Append output to file2
sort <file1 >file2 &
# Background job
(ls -l; a.out) &
# Run two background commands sequentially
sort <file | wc
# Two-process pipeline
sort <f | uniq | wc
# Three-process pipeline
ls -l *.c
# List all files ending in .c
ls -l [a-c]*
# List all files beginning with a, b,or c
ls -l ?
# List all one-character file names
ls \?
# List the file whose name is question mark
ls ’???’
# List the file whose name is three question marks
v=/usr/ast
# Set shell variable v
ls -l $v
# Use shell variable v
PS1=’Hi! ’
# Change the primary prompt to Hi!
PS2=’More: ’
# Change the secondary prompt to More:
ls -l $HOME
# List the home directory
echo $PATH
# Echo the search path
echo $?
# Echo exit status of previous command in decimal
echo $$
# Echo shell’s pid in decimal
echo $!
# Echo PID of last background process
echo $#
# Echo number of parameters (shell script)
echo $2
# Echo second parameter (shell script)
echo "$2"
# Echo second parameter without expanding spaces
echo $*
# Echo all parameters (shell script)
echo $@
# Echo all parameters (shell script)
echo "$@"
# Echo all parameters without expanding spaces