LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-08-2003, 05:02 PM   #1
Askari
LQ Newbie
 
Registered: Nov 2003
Posts: 2

Rep: Reputation: 0
Scripting


ok I'm a newb at this so I'm not sure if I'm doing this right. Any suggestions would be appreciated. I need to make a script that takes in a userid as an argument. it then takes the userid to obtain the user's name from the /etc/passwd file with the cut command. it should then prompt if the user wants to enter another userid. if yes, then it'll repeat the script, if no, then it'll end. Thanks
#!/bin/bash
echo
===================================================================
echo Welcome to Linux Login
echo Created by RC
echo ===================================================================

answer=y
while [ "$answer" = "y" ]; do
if [ $# = -lt 1 ]
then
echo -n "Enter userid: "
read userid
fi
if [ "$1" ]; then
x=$1
else
user=$userid
new=$(grep $userid /etc/passwd | cut -f5 -d
echo $new
echo "Would you like to enter another userid? (y)es or (n)o"
if [ "answer" != "y" ]
then
read answer
fi
done
 
Old 12-09-2003, 09:25 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Here are some changes, you will need to make one or two more for your homework.
[code]
(Hint: use code tags )
Code:
answer="y"
while [ "$answer" = "y" ]; do
   if [ $# -lt 1 ] ; then
     echo -n "Enter userid: "
          read userid
     else
          userid="$1"
   fi
   echo "`$(grep '$userid' /etc/passwd | cut -f5 -d`"
   echo "Would you like to enter another userid? (y)es or (n)o "
   read answer   
done
-- note that you will keep checking for the same userid if you ask to continue.
 
  


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 06:01 AM.

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