Shell Programming
Shell Programming
Implementation
% cd /usr/tmp
% pwd
/usr/tmp
% pushd ~rvrpci
% pwd
/cis/staff/rvrpci
% dd if=input.dat of=output.dat
bs=2 conv=swab
$0 $1 $2
command $argv[1] $argv[2]
$#argv
Indicates how many arguments are present
In this case, 2
#!/bin/csh -f
dd if=$1 of=$2 bs=2 conv=swab
% ls -l swap_bytes
-rw------- ... swap_bytes
% chmod u+x swap_bytes
% ls -l swap_bytes
-rwx------ ... swap_bytes
% swap_bytes
usage: swap_bytes input_file output_file
exit 0
Indicates successful command completion
% swap_bytes
usage: swap_bytes input_file output_file
$<
Rolando V. Raqueño Tuesday, April 8, 2025
Interactive swap_bytes
#!/bin/csh -f
if ( $#argv != 2 ) then
echo -n "Please enter the input file> "
set input=$<
echo -n "Please enter the output file> "
set output=$<
endif
dd if=$input of=$output bs=2 conv=swab
% swap_bytes
Please enter the input file> input.dat
Please enter the output file> output.dat
% pnmfile test_data.pgm
test_data.pgm: PGM plain, 3 by 3 maxval 255
end
• No error trapping