Determine a shell variable exists in file?

Hi Folks,

Trying to build up a script that will lookup a username invoked as:

./buildscript.sh <username>

This should take <username> and look it up in <username_file> and prepare for further processing. Here is the snippet that isn't working just right:

user=$1
if [[ !{$user = '{grep $user username_file}' -eq 1 ]]; then
  echo usage: $0 username
  echo "  where username is your domain username"
  exit 1
fi

Please be gentle, my script-fu is weak.

You could do something like:

#!/bin/bash

if [ $# -ne 1 ]
then
        echo "Usage: $0 <username>"
        exit 1
else
        user="$1"
        if grep -q "$user" username_file
        then
                echo "User: $user present"
        else
                echo "User: $user not present"
        fi
fi
1 Like