Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Beginner bash - basic shell script 'while' help... Post 303005739 by Aia on Sunday 22nd of October 2017 02:59:08 PM
Old 10-22-2017
Quote:
Originally Posted by Meta
[...]
Code:
#!/bin/bash
while true; do
        echo "What is your name?"
        read name
        echo "What is your age?"
        read age
        echo "What is your sex?"
        read sex
        echo "so you're a $age old $sex called $name, is that right?"
        read right
                if test $right = Yes
                then echo "Great, thanks!"
                elif test $right = No
                then echo "Please enter your information again."
        fi
done

It's just a simple script that asks the user to input their information, and confirm that the details provided are correct. [...]
Quote:
Originally Posted by Meta
Excellent, "break" worked a treat! Many thanks.

Any suggestions as to where to find some decent tutorials on using "while" loops? I don't just want to throw a messy script together and call it quits, I actually want to learn how to do this properly?

Appreciate the quick reply though. Smilie
Let me give you a few tasks that will help you experiment toward your goal as highlighted in read
Before you utilize any input validate it as something you were expecting.
e.g.
How would you validate that the user have entered a proper gender? What if the user enters "Neutral" or any other variation of modern gender answers? What if it just pressed the ENTER/Return key?
How would you validate an age? What if the user enters 159 or 0 or just the ENTER/Return key?
How would you validate a name? Would you accept "Shakespeare's Hamlet" inputted as string for a name?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script for Beginner

I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ...... Please help. Thx :confused: (3 Replies)
Discussion started by: aaron_fong
3 Replies

2. Shell Programming and Scripting

Unix beginner. Need some very basic help.

Hey all I'm working on a script that will scour a directory of 6000+ files for a line that at the end has a number. Something like 'The number of outputs is: 39200' I'm trying to devise a script to add all of these numbers up, so far I have the grep statement that pulls out each individual... (7 Replies)
Discussion started by: TiznaraN
7 Replies

3. Shell Programming and Scripting

Beginner shell script help

. ./testFile.sh url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv wget $url$s1$suf; sleep 10; cat header.txt > $s1.txt; chmod 777 $s1.txt; sed '1d' table.csv?s\=$s1 >> $s1.txt; rm -Rf table* Very new at shell scripting as you can see... (3 Replies)
Discussion started by: harte
3 Replies

4. UNIX for Dummies Questions & Answers

Basic Unix bash script help

Hello there Been using Unix bash scripting for two days now so am very new to this. I am currently doing a project now and i'm basically making a noughts and crosses game (or tic tac toe). I have created the board using an array. When I try and check to see if the array is empty using an If... (3 Replies)
Discussion started by: ChrisHoogie
3 Replies

5. Shell Programming and Scripting

Shell script (beginner) need help...

Hello, I'm new to Sheel script and I need your help for a script I need to develop (for me). Indead, I have a software which log all entry from internet and save it in text file. But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
Discussion started by: acidoangel
5 Replies

6. Homework & Coursework Questions

Shell Script (beginner)

1. The problem statement, all variables and given/known data: Arguments: http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg I am given these three arguments. $1, $2, $3 The first argument is the path to a directory. So, how would I go into the directory and compare files? I... (5 Replies)
Discussion started by: spider-man
5 Replies

7. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

8. Shell Programming and Scripting

Help in making a basic bash script

Hi All, I am trying to monitor CPU load of few processes, with the same name. The output that I get from top is the following 28171 root 20 0 1089m 21m 3608 S 103 0.3 15:16.89 /opt/ppp//h264rtptranscoder.bin --videoPort=14504 --audioPort=14505 27589 root 20 0 1060m 23m... (3 Replies)
Discussion started by: liviusbr
3 Replies

9. Shell Programming and Scripting

Beginner here, how to call a bash-script from python properly?

Hi everyone, i have the following script.sh: foo='lsusb | grep Webcam | cut -c16-18' sudo /home/user/public/usbreset /dev/bus/usb/001/$foo when i try to call this script from python using subprocess.call("script.sh", shell=True) it seems that only 'sudo /home/user/public/usbreset' is being... (6 Replies)
Discussion started by: hilfemir
6 Replies

10. Shell Programming and Scripting

If condition shell script beginner

Hi all I have the folloing process that needs checking often: ps -ef | grep ih bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4 bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies
POSIX_GETEUID(3)							 1							  POSIX_GETEUID(3)

posix_geteuid - Return the effective user ID of the current process

SYNOPSIS
int posix_geteuid (void ) DESCRIPTION
Return the numeric effective user ID of the current process. See also posix_getpwuid(3) for information on how to convert this into a use- able username. RETURN VALUES
Returns the user id, as an integer EXAMPLES
Example #1 posix_geteuid(3) example This example will show the current user id then set the effective user id to a separate id using posix_seteuid(3), then show the difference between the real id and the effective id. <?php echo posix_getuid()." "; //10001 echo posix_geteuid()." "; //10001 posix_seteuid(10000); echo posix_getuid()." "; //10001 echo posix_geteuid()." "; //10000 ?> SEE ALSO
posix_getpwuid(3), posix_getuid(3), posix_setuid(3), POSIX man page GETEUID(2). PHP Documentation Group POSIX_GETEUID(3)
All times are GMT -4. The time now is 12:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy