LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2003, 09:56 AM   #1
Askari
LQ Newbie
 
Registered: Nov 2003
Posts: 2

Rep: Reputation: 0
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!
 
Old 11-26-2003, 10:25 AM   #2
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
new to scripting mifan Linux - Newbie 2 08-17-2005 12:10 PM
another help with scripting?! ice99 Programming 2 08-09-2005 08:56 AM
Need help scripting Tamara Programming 7 06-06-2005 02:06 AM
Scripting Help Please Jazinator Linux - Newbie 7 10-17-2004 06:35 PM
scripting bforest Linux - Newbie 4 05-11-2004 02:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration