About 108,000 results
Open links in new tab
  1. How do I write a 'for' loop in Bash? - Stack Overflow

    Sep 8, 2008 · I commonly like to use a slight variant on the standard for loop. I often use this to run a command on a series of remote hosts. I take advantage of Bash's brace expansion to create for loops that allow me to create non-numerical for loops. Example: I want to run the uptime command on frontend hosts 1-5 and backend hosts 1-3:

  2. How to loop in bash script? - Stack Overflow

    Oct 24, 2010 · i have following lines in a bash script under Linux: ... mkdir max15 mkdir max14 mkdir max13 mkdir max12 mkdir max11 mkdir max10 ... how is the syntax for putting them in a loop, so that i don'...

  3. Loop through an array of strings in Bash? - Stack Overflow

    Jan 16, 2012 · Note that the double quotes around "${arr[@]}" are really important. Without them, the for loop will break up the array by substrings separated by any spaces within the strings instead of by whole string elements within the array. ie: if you had declare -a arr=("element 1" "element 2" "element 3"), then for i in ${arr[@]} would mistakenly iterate 6 times since each string becomes 2 substrings ...

  4. How do I iterate over a range of numbers defined by variables in …

    Oct 4, 2008 · Bash is a great shell and I use it interactively, but I don't put bash-isms into my scripts. Scripts might need a faster shell, a more secure one, a more embedded-style one. They might need to run on whatever is installed as /bin/sh, and then there are all the usual pro-standards arguments.

  5. unix - Shell script "for" loop syntax - Stack Overflow

    seq is relatively new. I only found out about it a few months ago. But you can use a 'for' loop!! The disadvantage of a 'while' is that you have to remember to increment the counter somewhere inside the loop, or else loop downwards. –

  6. bash - Read user input inside a loop - Stack Overflow

    Aug 23, 2020 · example 3 is perfect. removing cat input_file | while also has the benefit, that inside the while loop, you can modify variables of the parent scope. see also A variable modified inside a while loop is not remembered. the cat input_file could be moved to a process substitution like done 3< <(cat input_file) –

  7. How to iterate over arguments in a Bash script

    It is a cover script that does both a delta (think check-in) and a get (think check-out). Various arguments, especially -y (the reason why you made the change) would contain blanks and newlines. Note that the script dates from 1992, so it uses back-ticks instead of $(cmd ...) notation and does not use #!/bin/sh on the first line.

  8. How to loop through dates using Bash? - Stack Overflow

    Jan 1, 2015 · Now I want to loop through a range of dates, e.g. 2015-01-01 until 2015-01-31. How to achieve in Bash? Update: Nice-to-have: No job should be started before a previous run has completed. In this case, when executeJobs.py is completed bash prompt $ will return. e.g. could I incorporate wait%1 in my loop?

  9. Looping through the content of a file in Bash - Stack Overflow

    Oct 6, 2009 · If you need to know the line number, add a counter to your while read -r loop, or use nl -ba to add a line number prefix to each line before the loop. – tripleee Commented Feb 7, 2020 at 9:44

  10. Incrementing a variable inside a Bash loop - Stack Overflow

    Dec 19, 2013 · I'm trying to write a small script that will count entries in a log file, and I'm incrementing a variable (USCOUNTER) which I'm trying to use after the loop is done. But at that moment USCOUNTER looks to be 0 instead of the actual value.

Refresh