check arguments in list unix

I have a list of names in a list (say name.txt) which has the set of name lists one by one.

name.txt

babu
praveen
kamal
sneha

This name will be passed as run time argument $1 in my bash script.
Now I have to do a match to check if the inputted name is in my list or not.

If it’s not there then I will print saying invalid name and exit. Can you help me with this?

I have tried this with

if [[ "$1" != "babu" || "$1" != "praveen" || "$1" != "kamal" ... ]]; then
    exit
fi

but this doesn’t look good professionally.

Is there any other simple and decent way to achieve this?


Source: bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.