Check if /opt/ or /usr/ paths are contained in ``$PATH``: ::
case $PATH in
*/opt/* | */usr/* )
echo /opt/ or /usr/ paths found in \$PATH
*/opt/* )
echo /opt/ paths found in \$PATH
;;
*/etc/* )
echo /etc/ paths found in \$PATH
;;
*)
echo '/opt and /usr are not contained in $PATH'
;;
esac
or
case $PATH in
*/opt/* | */etc/* )
echo /opt/ or /etc/ paths found in \$PATH
;;
*)
echo '/opt and /usr are not contained in $PATH'
;;
esac
Loops
-----
...
...
@@ -460,16 +479,18 @@ list of given values and run the given statements for reach run:
*list* is a list of strings, separated by whitespaces
Examples:
List all files in /tmp in a bulleted list: ::
List filenames and count number of sequences in every FASTA file in ./sequence_files: ::
for FILE in /tmp/*
for FILE in ./sequence_files/*.fasta
do
echo " * $FILE"
grep -c '\>' $FILE
done
or
for FILE in `ls /tmp`
for FILE in `ls ./sequence_files/*.fasta`
do
echo " * $FILE"
grep -c '\>' $FILE
done
...
...
@@ -541,10 +562,6 @@ options and arguments.
Configurable Scripts
--------------------
Any value - be it paths, commands or options - that is specific to individual
applications or your script, should not be "hardcoded" (i.e. used literally
within the script) but assigned to variables:
Using Variables
^^^^^^^^^^^^^^^
...
...
@@ -553,7 +570,7 @@ applications or your script, should not be hardcoded (i.e. used literally
within the script). Instead you should use variables to refer to them:
Bad example:
You have to change two instances of the path each time you want to list another directory::
You have to change two instances of the path each time you want to list another directory::
#!/bin/sh
...
...
@@ -561,7 +578,7 @@ Bad example:
ls /etc
Good example:
The path is now in a variable and only one instance has to be changed each time (less work, less errors)::
The path is now in a variable and only one instance has to be changed each time (less work, fewer errors)::
#!/bin/sh
...
...
@@ -570,7 +587,7 @@ Good example:
echo "The directory $MYDIR contains the following files:"
ls $MYDIR
Of course, you'll still have to modify the script each time you want to list the content of another directory. A more flexible way of customization would be to use a settings file.
Of course, you'll still have to modify the script each time you want to list the content of another directory. A more flexible way of customization would be to use a settings file.
Using a Settings File
^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -599,7 +616,7 @@ Defining your own Commandline Options and Arguments