Scripting--need to create a 2 loops in a loop--can someone help
Explanation:
Write a script to be saved on our server as 'project2.sh' that does the following things: • Asks the user how many times they want to loop • Displays a growing line up to 50 “-” and then shrinks back to nothing Sample output from script being run: How many times do you want to loop? 1 |
Please post your script and explain how it does not do what you want.
|
project sh
here is what I have so far
#!/bin/bash #How many times do you want to loop? outerCounter=0 while [$counter -lt "50"] do echo counter let counter=$counter+1 done let outerCounter=$outerCounter+1 done |
As per Catkin, what if any problems do you have with that.?
I would point out that this Code:
while [$counter -lt "50"] I also recommend [[]] instead http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS You may find these useful http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ For debug purposes,use 'set -xv' thus Code:
#!/bin/bash |
Code:
#!/bin/bash You don't yet have anyway to get input from the user---take a look at the "read" command. |
Looping
Here is what I have but receiving errors:
#!/bin/bash #How many times do you want it to loop outerCounter=0 #this is our OUTER Loop while [ $counter -lt "50" ]; do counter=0 #This is our INNER Loop while [ $counter -lt "50" ]; do #code goes here echo counter #increment couter let counter=$counter+1 done let outerCounter=$outerCounter+1 done |
Once again, please use CODE tags and formatting. You can put in the tags by hand--or use the "#" button in the advanced editing mode. We want it to look something like this:
Code:
#!/bin/bash Here is what I see so far: 1. You don't do anything with "outerCounter"---should you be testing it in the outer loop? 2. To see the value of a variable, you need "$"---eg echo $counter Did you read up on the "read" command?---you'll need that to get the user to input data. |
sorry
The error I am now getting is line 7: [: -lt: unary operator expected
thanks |
Quote:
|
tim*
I would encourage you to respond to ALL of the inputs you are getting----if someone gives you 3 suggestions, then I would respond to all three. |
Might also pay you to look at the test command ([ && [[ are synonyms for this) and see what -lt is used for, ie. numbers or strings
|
All times are GMT -5. The time now is 02:52 PM. |