A simple shell script demonstrating access to arguments.
echo My name is $0
echo My process number is $$
echo I have $# arguments
echo My arguments separately are $*
echo My arguments together are "$@"
echo My 5th argument is "'$5'"
l [file|directories…] - list files
Short Shell scripts can be used for convenience.
Note: “$@” like $* expands to the arguments to the script, but preserves the integrity of each argument if it contains spaces.
ls -las "$@"
Count the number of time each different word occurs in the files given as arguments, e.g. word_frequency.sh dracula.txt
sed 's/ /\n/g' "$@"| # convert to one word per line
tr A-Z a-z| # map uppercase to lower case
sed "s/[^a-z']//g"| # remove all characters except a-z and '
egrep -v '^$'| # remove empty lines
sort| # place words in alphabetical order
uniq -c| # use uniq to count how many times each word occurs
sort -n # order words in frequency of occurrance
Print the integers 1…n if 1 argument given.
Print the integers n…m if 2 arguments given.
if test $# = 1
then
start=1
finish=$1
elif test $# = 2
then
start=$1
finish=$2
else
echo "Usage: $0 <start> <finish>" 1>&2
exit 1
fi
for argument in "$@"
do
# clumsy way to check if argument is a valid integer
if echo "$argument"|egrep -v '^-?[0-9]+$' >/dev/null
then
echo "$0: argument '$argument' is not an integer" 1>&2
exit 1
fi
done
number=$start
while test $number -le $finish
do
echo $number
number=`expr $number + 1` # or number=$(($number + 1))
done
```