0

I currently have a Unix program where I'm trying to correctly use a getopts while loop with a case command nested inside. Inside that getopts while loop is a case command and inside the case case is two options that both are until loops. Here is the current code:

while getopts ufn: user
do

    case "$user"

    in

            u)

                    tty=$(who | grep "$user " | cut -d\  -f 2)
                    until who | grep "$user "  > /dev/null
                    do
                            sleep 60
                    done
                            echo "$user has logged onto $tty";;
            f)

                    until find | home/students/shaunkolkman/$user
                    do
                            test -d $user || test -f $user
                            sleep 20
                    done
                            echo "$user is a file or directory";;

    esac

done

user=$1

Option u is a until loop that looks for someone to log on and show what tty that user is on. Option f is a until loop finding either a file or directory. The until loops work perfectly fine. Option n will be added later once I figure out this problem.

Here's a example snipppet with a description of what is going on.

./mon4 -f vex

The issue I'm facing is that the f from -f is being seen as the variable. Along with -f still being read as a option from getopts. I don't understand why vex isn't read as the variable.

chepner
  • 497,756
  • 71
  • 530
  • 681
user1725798
  • 49
  • 1
  • 2
  • 7

1 Answers1

0

As has been said, options that require a value need a colon

while getopts uf:n: user
#               ^
#              /
#    notice ---

Example

Zombo
  • 1
  • 62
  • 391
  • 407