LinuxQuestions.org
Review your favorite Linux distribution.
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, 06: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, 10:25 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:10 PM
another help with scripting?! ice99 Programming 2 08-09-2005 09:56 AM
Need help scripting Tamara Programming 7 06-06-2005 03:06 AM
Scripting Help Please Jazinator Linux - Newbie 7 10-17-2004 07:35 PM
scripting bforest Linux - Newbie 4 05-11-2004 03:45 AM


All times are GMT -5. The time now is 05:23 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration