Sponsored Content
Full Discussion: Help with loops?
Top Forums UNIX for Advanced & Expert Users Help with loops? Post 302921810 by sea on Monday 20th of October 2014 11:54:59 AM
Old 10-20-2014
Some more examples, hope they help Smilie

Code:
# for loop with a case statement
for planet in Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto;do
	case $planet in
	Earth)	echo "You live here on $planet"
		;;
	Pluto)	echo "$planet is no longer a planet"
		;;
	*)	echo "$planet"
		;;
	esac
done

# while loop with a counter
C=0
MAX=100
printf '\n\n\t%s\n\n' "Current numbers:"
while [[ $C -le $MAX ]];do
	printf '%s' "$C "
	c=$[ $C % 2 ]
	[[ 0 -eq $c ]] && echo "... is an equal number"
	((C++))
done

Since you pass all arguments as a single quote (all planets/words are within the same quotes), it is handled as a single string.
Therefor, there is only 1 entry, holding all the words.

However, passing an array is diffrently, there you should use: "${@}"
Here, the quotes will embrace each single element of the array, eg: a filename with whitespace in its name will remain 'valid'.

Hope this helps
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

loops?

hello....very new user to unix...and i have a question..i am not sure if there is such a thing For example...the user is asked if he likes Bananas....if he says yes.... echo You like Bananas $name at the end of the script it echos all that the user has entered so they can read it.... but... (1 Reply)
Discussion started by: jonas27
1 Replies

2. Shell Programming and Scripting

Loops within loops

I am running on HPUX using ksh. I have a script that uses a loop within a loop, for some reason the script seems to hang on a particuliar record. The record is fine and hits the condition in Blue. If I kill the 1st loop process the script continues on with no problem. Begin code> <Some... (8 Replies)
Discussion started by: bthomas
8 Replies

3. UNIX for Dummies Questions & Answers

While Loops

I'm trying to create a loop that will prompt the user for 15 values, not forcing them to enter all 15. If the user enters through one or more of the prompts the null value needs to be converted to 0, otherwise set the parameter = to the value entered: ex. Please enter file no #1: 17920 ... (4 Replies)
Discussion started by: vdc
4 Replies

4. UNIX for Dummies Questions & Answers

two loops

Hi, how can I use "for" to have two loops : this is my script : for i in (A B C) do for j in (a b c) do echo $i$j done done #End I want to print out Aa Ab Ac .... But I have error message : syntax error at line 1 : `(' unexpected Many thanks before. How should I use "for" ?? (2 Replies)
Discussion started by: big123456
2 Replies

5. Shell Programming and Scripting

while loops

Hi I've a file like so: Now, I want to read my file and take ex. the Media ID and the Type for each groups of Media (Media1,Media2,...,Media(n): cat /tmp/file|\ while read FILE do while $(FILE|cut -d: -f1)=Media$i do #here will be some test, ex: #if Media ID < 23 ... (4 Replies)
Discussion started by: nymus7
4 Replies

6. UNIX for Dummies Questions & Answers

Help with While Loops

I am traversing down a list, and I am not quite sure how to tell the loop to break when it's done going through the file. #!/bin/sh while : do read list <&3 echo $list done is the code. The file "list" is simply 5 4 3 2 1 any advice on how to break the loop after the file is... (1 Reply)
Discussion started by: MaestroRage
1 Replies

7. Shell Programming and Scripting

Help with the 2 for loops

#!/bin/bash IFS=$'\n' A= a c b t g j i e d B= t y u i o p counter=0 found="" for i in $(cat $A) do for j in $(cat $B) do if then found="yes" fi done if then (1 Reply)
Discussion started by: vadharah
1 Replies

8. Shell Programming and Scripting

Loops

Hi All, I want to execute a script the number of times a user enters. Please can you advise on hor can I do the same. Many Thanks, Shazin (4 Replies)
Discussion started by: Shazin
4 Replies

9. UNIX for Dummies Questions & Answers

loops with tr

Hello, I'm not sure if this is more appropriate for the 'unix for dummies' or the 'unix for experts' forum because I'm new to this forum and this is the second topic I've discussed, but if you could let me know which one was more appropriate for something like this, please do! So in tr (an... (2 Replies)
Discussion started by: juliette salexa
2 Replies

10. UNIX for Dummies Questions & Answers

Need help with for loops

Why wont my for statements work? Im trying to get this script to swich to a user an if you put in a start/stop/or restart paramater to do just that for each user. I commented out the actual start/stop actions to test it just by using echos and not do anything hasty in the environment but it... (0 Replies)
Discussion started by: LilyClaro
0 Replies
QONK(6) 																   QONK(6)

NAME
qonk - Small build-and-conquer strategy game with very simple rules SYNOPSIS
qonk [number of planets] [number of AI players] DESCRIPTION
This manual page was written for the Debian(TM) distribution because the original program does not have a manual page. Most of the text is taken verbatim from the author's webpage. qonk is a small build-and-conquer strategy game with very simple rules. A complete game only lasts for a few minutes and can be a fun break away from work or whatever you're doing. The setting of the game is a solar system of planets. Your goal is to conquer all of the planets in the game by sending ships there. Planets that are under your control generate new ships. Simple AI players are playing against you. As you gain more experience throughout the game, more AI players have to be kicked out of bigger solar systems. The game is currently very much in beta. The game engine itself is fully functional. A lot of things have to be added to make this a mature game (like menus and stuff), but since the engine itself works, Qonk is already very playable. Although the game engine is prepared to run under different modes, the game always defaults to 1024x768 resolution, and goes into fullscreen modus to run qonk. (because of beta status) OPTIONS
In order to change between levels, the game had to exit and parameters for the game and its level had to be entered from the command line. A small modification have been introduced for making this automatically. Nevertheless, you can always start in any level you prefer. Qonk can be given two numeric parameters, the first denoting the number of planets in the solar system, the second gives the number of enemy AI players. Successive levels of the game are defined by two such parameters. number of planets Total number of planets in the solar system. number of AI players The number of enemy AI players you will compete with. HOW TO PLAY
You select ships and send them out to planets, to attack or fortify them. A ship that arrives at an enemy planet dies and kills an enemy ship, residing on that planet, along with it. If no enemy ships are based on the planet, you take over the planet. Planets under your control grow new ships for you to send around. You control white planets and white ships. Colored planets belong to the opponent players. Gray planets are not controled by a player and can easily be conquered, once its resident neutral ships are destroyed (about 2-4 of them on each neutral planet). There are two types of planets in the solar system. There are planets orbiting around the "sun" and moons orbiting around the planets. There are as many moons as planets in each solar system. Some planets may have more moons than others. A planet is expected to generate twice as many ships as a moon in the same amount of time. Some planets/moons build ships more quickly than others. Each ship also has a random speed. Select ships by dragging your left mouse button. A ship can only be selected for an action if it resides on a planet. Use the right mouse button to send selected ships to the nearest planet to the mouse pointer. If you want to select all of the available ships, press A. As you conquer more planets, more ships are built in parallel. Try to conquer as many planets as possible, so that many new ships are constructed and you can reign over the solar system. There are some extra keys that can be used: E While pressing E, the ships of enemy players are shown, so this is kind of a cheat button. P Pause and unpause the game. S Save a screenshot (screenshot.bmp) of the game. PLAYER RANKING
The rank of a player is not only based on the number of planets the player possesses, but also on the number of ships. A planet gives a player 2 points, a moon gives 0.999 points, and each ship adds another 1/3 of a point. A moon is thus worth just under 3 ships. Players with the highest amount of points rank highest. AUTHOR
Qonk was written by Anthony Liekens and Robert Schuster. This manual page was written by Martin Ferrari <martin.ferrari@gmail.com> for the Debian(TM) system, taking text from the game author's webpage: http://anthony.liekens.net/index.php/Computers/Qonk COPYRIGHT
Copyright (C) 2006, Anthony Liekens <anthony@liekens.net> Copyright (C) 2007, Robert Schuster <robertschuster@fsfe.org> This manpage Copyright (C) 2006 Martin Ferrari 2006-06-19 QONK(6)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy