LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need some scripting help (https://www.linuxquestions.org/questions/programming-9/need-some-scripting-help-120142/)

Askari 11-26-2003 09:56 AM

Need some scripting help
 
Hi all you very nice people
I was wondering how you would create a script that will take in a user id as an argument from the command line. I need the script to check if an argument was given and if not, prompt for one. Then, using the userid, the script should obtain the user's name from the /etc/passwd file. THe script should then prompt if the user wants to enter in another userID. If yes, then the process should repeat itself or if not, then the script should exit. Thanks a lot!

mfeat 11-26-2003 10:25 AM

here's a simple example to get started with, it shows how to check if an argument was given and
how to get the username from /etc/passwd, the prompting and looping would have to be added.

Code:

#!/bin/bash
if [ $# = 0 ] ; then
  echo  Usage $0: {userid}
else
        userid=$1
        echo username=`grep ^${userid}: /etc/passwd | awk -F: '{print $5}'`
fi

this assumes that the layout of /etc/passwd on your machine follows the same format
where column 5 (delimited by colons) is the user name


All times are GMT -5. The time now is 03:07 AM.