LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2006, 08:42 PM   #1
Urlryn
LQ Newbie
 
Registered: Mar 2004
Location: Houston, TX
Posts: 10

Rep: Reputation: 0
Linux Bash Script Help


Hiya all....

Trying to do a simple script that outputs to a file then ends if the inputed info is correct. But if the info is incorrect they have to go back to the start of the script and remove the file and create a new blank one. This is the part i'm having a bit of trouble

Code:
#!/bin/bash

touch user_profiles.txt 
echo "Please enter you full name =>"
read full_name > user_profiles.txt
clear

echo "Please enter you street address =>"
read number street street_name >> user_profiles.txt
clear

echo "Please enter your City =>"
read city >> user_profiles.txt
clear

echo "Please enter your State (enter entire name no abbreviations) =>"
read state >> user_profiles.txt
clear

echo "Please enter your zip code =>"
read zip >> user_profiles.txt
clear

echo $full_name
echo $number $street $streetname
echo $city, $state $zip

echo "Is this correct? (please enter 1 for yes and 0 for no =>"

read correct
        if [ $correct -eq 0 ]; then
                echo "Thank you for your time, Have a nice day."
        else
                echo "`rm user_profile` ; `bash info`"
        fi
This is what i got so far....please be gentle =)
 
Old 04-29-2006, 10:41 PM   #2
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
I debugged your code and made it more modular.
this should work for you.
Code:
#!/bin/bash

file=user_profiles.txt
echo -n > user_profiles.txt
clear

getvar(){                        # getvar prompt var
   echo $1
   read $2
   clear
}
getvar "Please enter you full name =>" full_name
echo $full_name >> $file
getvar "Please enter you street address =>" address
echo $address >> $file
getvar "Please enter your City =>" city
echo $city >> $file
getvar "Please enter your State (enter entire name no abbreviations) =>" state
echo $state >> $file
getvar "Please enter your zip code =>" zip
echo $zip >> $file

echo $full_name
echo $address
echo $city, $state $zip

echo "Is this correct? (y/N) =>"

read correct
        if [[ "$correct" = "Y" ]] || [[ $correct = "y" ]]; then
                echo "Thank you for your time, Have a nice day."
        else
                echo "removing user_profile.txt..." ; sleep 3s
                exec $0
        fi
 
Old 04-29-2006, 11:45 PM   #3
Urlryn
LQ Newbie
 
Registered: Mar 2004
Location: Houston, TX
Posts: 10

Original Poster
Rep: Reputation: 0
Ohhh interesting...thank you very much!

Urlryn
 
  


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
How to get linux distribution with command bash or script gigix Linux - Distributions 5 04-28-2005 06:17 AM
Question about Bash script for Linux Linh Programming 9 04-21-2004 11:54 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Telnet in a bash script in linux tiger Programming 3 08-01-2001 07:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:29 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