LinuxQuestions.org
Review your favorite Linux distribution.
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 01-17-2012, 05:39 AM   #1
jayantbhagat
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Rep: Reputation: Disabled
AGE=`cat ${USERNAME}_DAT


#!/bin/sh

# Prompt for a user name...
echo "Please enter your name:"
read USERNAME

# Check for the file.
if [ -s ${USERNAME}_DAT ]; then
# Read the age from the file.
AGE=`cat ${USERNAME}_DAT`
echo "You are $AGE years old!"
else
# Ask the user for his/her age
echo "How old are you?"
read AGE

if [ "$AGE" -le 2 ]; then
echo "You are too young!"
else
if [ "$AGE" -ge 100 ]; then
echo "You are too old!"
else
# Write the age to a new file.
echo $AGE > ${USERNAME}_DAT
fi
fi
fi




In this program what is AGE=`cat ${USERNAME}_DAT and how it work .....
 
Old 01-17-2012, 05:48 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Honestly, this seems like homework.... Can't you see what it is? This is a bash script, and just by looking at it, I can see what it is, and what it does.
 
Old 01-17-2012, 10:06 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.

Actually, it's not a bash script. Since it begins with #!/bin/sh, and doesn't contain any bash-specific syntax, it's just a generic posix-compliant script.

Still, everything written there should be covered in just about any bourne-compatible shell tutorial out there. Here's my favorite:

http://mywiki.wooledge.org/BashGuide


BTW, $(..) is highly recommended over `..`.
 
Old 01-17-2012, 01:38 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Oops, my fault. It's a shell script Thanks for the correction though! I read it too fast.....
 
Old 01-17-2012, 01:48 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,362

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
Code:
AGE=`cat ${USERNAME}_DAT`
dumps the contents of the ${USERNAME}_DAT file (eg: Johnny_DAT) into the variable "AGE"

Last edited by suicidaleggroll; 01-17-2012 at 01:50 PM.
 
Old 01-18-2012, 12:48 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
To see what's going on, amend the top of the script
Code:
#!/bin/sh

set -xv
which will show you what the parser is doing.
Useful links
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Note that 'sh' & 'bash' are different shells, but very similar.
To fully take advantage of those links, use bash instead of sh.
 
  


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
Cat 6 Cat 5e cable question babbab Linux - Networking 1 04-07-2010 03:33 PM
fedora 8 asking username but during installation i dint give any username ?? herevenku Linux - Newbie 2 08-25-2008 05:37 AM
cat in asm/ cat --show-all option Tux Linux - Software 1 09-02-2006 10:31 PM
Can't get Age of Empires II: Age of Kings started (I've could it before !!!) vegetassj2 Linux - Games 44 08-28-2005 05:59 PM
Java does "age" or "Age" matter when declaring an Int?? Laptop2250 Programming 3 10-13-2003 01:34 PM


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