I'm trying to make a command line tool out of a bash script. It is very simple:
grep ">" in_file >> out_file.
So I want to copy all lines containing '>' from the first file to the second. I need a tool that I could run from the command line like this:
./tool.sh -input in_file -output out_file
-input and -output here are to keys.
I tried the code below:
while getopts "i:o:"
do
case $Option in
i) input=$OPTARG;;
o) output=$OPTARG;;
esac
done
grep -n '>' input >> output
But I got an error: tool: input: No such file or directory.
What is wrong here ? And also I want make the 'in' key to be able to take more than one arguments. How can I do this ? I guess I just don't understand correctely how does the getopts work but I didn't find any good description.
$before the variable names.