I am switching away from BSD to completely Linux.
Script in Ubuntu 16.04

```
#!/bin/sh
while (( "$#" )); do
   case "$1" in
    -i | --ignore-case)
        [ $# -ne 2 ] && echo "2 arguments i needed" && exit 1
        case_option=-i
        ;;
    -*)
        echo "Error: Unknown option: $1" >&2
        exit 1
        ;;
     *) # No more options
        break
        ;;
   esac

   shift
done

# -o, if not, then ...
find $HOME ! -readable -prune -o \
    -type f -name "*.tex" -exec grep -l $case_option "$1" {} + | vim -R -

```

Mistake is in looping. 

* `sh ./script masi` returns the same output as the expected output.
* Run `sh ./script -i masi`. Output: blank file. Expected output: list of results. STOUT is `./script: 2: ./script: 2: not found Vim: Reading from stdin...`.

Possible mistakes

* `while (( "$#" ))`
* ...

I cannot use the options at all for some reason. 

Moving to getopts - motivation by terdon's answer
-------------------------------------------------

[Tutorial](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html) and answer [here](https://stackoverflow.com/a/14458401/54964)

```
case_option=""

while getopts "i:" opt; do
    case $opt in
        i | ignore_case) 
            [[ $# -ne 2 ] && echo "2 arguments i needed" && exit 1
            case_option=-i
            ;;
        -*)
            echo "Error: Unknown option: $1" >&2
            exit 1
            ;;
        *) # No more options 
           break
           ;;
    esac
done

find $HOME ! -readable -prune -o \
   -type f -name "*.tex" -exec grep -l $case_option "$1" {} + | vim -R -

```

where 

* calling by `./script masi` or `./script -i masi`.

---

How can you do cases in `while` loop?