Simple Shell script help IF ELSE METHOD


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Simple Shell script help IF ELSE METHOD
# 1  
Old 02-05-2019
Simple Shell script help IF ELSE METHOD

I am a beginner at shell scripting and was trying to attempt this question : Write a shell script to prompt the user to input her/his age and print it on the screen only if the entered age is less than 30 (e.g. 𝑌𝑜𝑢𝑟 𝑎𝑔𝑒 𝑖𝑠 20 𝑦𝑒𝑎𝑟𝑠 𝑜𝑙𝑑

However, when I run the script below and enter in a number when prompted I get this error ":agescript: line 6: [5: command not found"


Code:
# Age script thing

echo "Hello, how old are you?"
agelimit=30
read agoe
if ["$agoe" -lt "$agelimit" ]; then
	echo "you're $agoe years old" 
	exit 0
	else
   	echo "you're old mate" 
	exit 0
	fi

# 2  
Old 02-05-2019
Welcome to the forum.


You need to enclose both the [ command and the trailing ] in spaces.
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Old 02-05-2019
In this line
Code:
if ["$agoe" -lt "$agelimit" ]; then

insert space atter braсket
Code:
if [ "$agoe" -lt "$agelimit" ]; then

This User Gave Thanks to nezabudka For This Post:
# 4  
Old 02-05-2019
thanks so much guys!!
This User Gave Thanks to ggrules For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on simple shell script

Hello, I need to create one very simple shell script that checks if the first character of the file ./pump.txt is 0 and in that case gives a message. If the first character is instead 1, it does give a different message. I have written: irr= head -c 1 ./pump.txt if ]; then echo... (4 Replies)
Discussion started by: dcaccount
4 Replies

2. Windows & DOS: Issues & Discussions

Method to run a shell script using shortcut key in keyboard with out logging to putty

Dear All, I want to run a shell script with out logging to putty but configuring it to a keyboard short cut it windows PC. Can this be done? I want this to rename a log in a specified folder in a system Thanks (8 Replies)
Discussion started by: Chi_SL
8 Replies

3. Shell Programming and Scripting

Help me with simple shell script.

Hello forum members, I have to redirect a output of command into a text file inside a script file but iam getting an errors.so please see below script and suggest me for corrections. #!/bin/ksh read IP_ADD echo nslookup $IP_ADD 2>&1| tee log1.txt cat /amex/gcst/siva/Testr/log1.txt... (6 Replies)
Discussion started by: rajkumar_g
6 Replies

4. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

5. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

6. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

7. UNIX for Advanced & Expert Users

which one method is best for debugging the shell script?

Hi All, How to debug the unix shell script? which one is the best way to do the debuging ? suggession would be appreciate Regards, Siva P Bangalore (2 Replies)
Discussion started by: psiva_arul
2 Replies

8. Shell Programming and Scripting

Simple Shell Script Need Help

I M TRYING TO DO SUM THING I M A NEW LEARNER TO SHELL SCRIPT PLZZZ HELP ME FRIENDS I M TRY TO DO SUM THING C IT AND HELP ME First open a .ctl file Copy the file into temp file Add A EXTRA FIELD “ext_date” with keeping value “##**&&” EG- EXT_DATE CONSTANT"******" Each time... (2 Replies)
Discussion started by: kulbir
2 Replies

9. UNIX for Dummies Questions & Answers

Any simple method to check date format (YYDDD)?

Hi Guru's, Are there any simple method to check the date format which is in "YYDDD" (ex: 08002 for 02-Jan-2008)? Eventhough this can be implemented in several way's, I need the simpler one. Any idea would be much appreciated. Thanks in advance, Mysore Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

10. UNIX for Advanced & Expert Users

I need of a simple shell script

Hi, I need of a simple shell script to launch a perl script. The complet path of the script is: /export/home/x2693/project/v02/appliancemanagement.pl (2 Replies)
Discussion started by: Minguccio75
2 Replies
Login or Register to Ask a Question