![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with while loop in shell script | rkrgarlapati | Shell Programming and Scripting | 16 | 07-29-2008 09:34 AM |
| Help shell script to loop through files update ctl file to be sql loaded | dba_nh | Shell Programming and Scripting | 1 | 04-15-2008 05:00 PM |
| Infinite Loop in Autosys while running a shell script, Manual run is fine | sharmagaurav_2k | Shell Programming and Scripting | 2 | 09-04-2007 05:20 AM |
| If then else loop in Shell script | pankajkrmishra | Shell Programming and Scripting | 4 | 07-31-2006 06:40 AM |
| Shell Script loop problem | MaxMouse | Shell Programming and Scripting | 1 | 07-26-2005 12:19 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am taking a class in UNIX and have written a script that needs to countdown from a number that is read in from the keyboard to zero. If no number is given the start of the countdown should default to 10.
I can't get this to do the default #! /bin/sh echo Enter a number here to countdown from a number to 0 read x if [ -n $x ]; then count=$x else count=10 fi while [ $count -ge 0 ] do echo $count seconds count=`expr $count - 1` done echo Off we go! Does anyone know what I am doing wrong? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
We're really not supposed to help folks with homework assignments on this board. But you've done most of the work and you're stuck on a very tricky problem.
if [ -n $x ] will not work, If there is nothing in x the command becomes: if [ -n ] So you need to use if [ -n "$x" ] Now when threre's nothing in x, the command becomes if [ -n "" ] |
|
#3
|
|||
|
|||
|
thank you
I actually realized that it had to be something similar to this last night as I had moved onto the next scrip to work on. I like UNIX scripting, but as with every other language I have taken it is the syntax that really throws me for a loop -- hee hee no pun intended.
Thank you for helping me. I will not ask for Homework help again. I don't want to get in trouble. |
|||
| Google The UNIX and Linux Forums |