My current Bash script looks like in the following. So far it's working except I have no idea how to make it so the two options -f and -o work together:
- the -o FILE option to display the most relevant information in a file passed as an argument (if the file does not exist an error message must be displayed)
- the option -f KEYWORD to display the lines containing the KEYWORD to from a file. This option must be used with the -o option
Thank you for any input
#!/bin/bash
function s_func()
{
filename="$1";
echo "when you're done saving information please write 'exit'"
script $filename.txt
}
function o_func()
{
filename="$1"
dest='/home/eya/'
if [ -f "$filename".txt ]; then
cat $filename.txt
else echo "file does not exist"
fi
}
function f_func()
{
keyword="$1"
filename="$2"
grep $keyword $filename.txt
}
while getopts ":s:o:f:" opt; do
case $opt in
s) s_func "$OPTARG";;
o) o_func "$OPTARG";;
f) f_func "$OPTARG";;
\?)echo "wrong option";exit 1;;
esac
done
shift $((OPTIND -1))