I am expanding the following function to include the option -i | --ignore-case
with error-handling
#!/bin/sh
[ $# -ne 1 ] && echo "1 argument is needed" && exit 1
find $HOME -type f -name "*.tex" -exec grep -il "$1" {} + | vim -
Expanded code
#!/bin/sh
################################
# Check if parameters options #
# are given on the commandline #
################################
while (( "$#" )); do
case "$1" in
-h | --help)
echo "help menu"
exit 0
;;
-i | --ignore-case)
[ $# -ne 2 ] && echo "1 argumenst i needed" && exit 1
find $HOME -type f -name "*.tex" -exec grep -il "$1" {} + | vim -
exit 0
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
shift # not sure if needed
done
# Do this if no cases chosen
[ $# -ne 1 ] && echo "1 argument is needed" && exit 1
find $HOME -type f -name "*.tex" -exec grep -l "$1" {} + | vim -
Result
haetex "TODO"
. Expected output is the same as output. Passed!haetex -i "TODO"
. Expected result: search with ignore-case. Result: blank file.
Why the option -i
is not working here?
$1
is-i
, the string to search for is in$2
, but you search for$1
.