![]() Start a while loop that is executed if the value of INDEX is less than 20.Set the value of the variable INDEX to 0.How does this apply to this specific case? Print Odd Numbers Using a Bash Script INDEX=0Īnd if we translate this logic into an actual Bash script… #!/bin/bash This applies to any Bash shell running on Unix-like systems (including MacOS).įirst of all let’s have a look at the generic structure of a while loop in Bash: while Īs long as the condition between square brackets is true the commands between do and done are executed. You will see how our script looks like if we hardcode the value of N in it, and then you will learn how to pass the value of N to the script as an argument via the Linux command line. Let’s create a loop that goes through N numbers and prints only the odd ones.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |