-1

I forgot the syntax and semantics for bash for loop and tried to find the manual in the system. I couldn't find it. It wasn't in man bash or man builtins. Where can I do a quick local reference on bash commands?

1 Answers1

1

Maybe you want more details than from the man pages. Here are also some examples

From man bash:

   for name [ in word ] ; do list ; done
          The list of words following in is expanded, generating a list of
          items.  The variable name is set to each element of this list in
          turn,  and  list is executed each time.  If the in word is omit‐
          ted, the for command executes  list  once  for  each  positional
          parameter that is set (see PARAMETERS below).  The return status
          is the exit status of the last command that  executes.   If  the
          expansion of the items following in results in an empty list, no
          commands are executed, and the return status is 0.

for (( expr1 ; expr2 ; expr3 )) ; do list ; done First, the arithmetic expression expr1 is evaluated according to the rules described below under ARITHMETIC EVALUATION. The arithmetic expression expr2 is then evaluated repeatedly until it evaluates to zero. Each time expr2 evaluates to a non-zero value, list is executed and the arithmetic expression expr3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in list that is executed, or false if any of the expres‐ sions is invalid.

Examples:

for i in *.txt;do echo textfiles: $i;done

for (( i=1; i<=20 ; i++ )) ; do echo $i;done

for i in .TXT;do mv $i ${i/.TXT/}.txt; done # "move .TXT *.txt"

sudodus
  • 46,324
  • 5
  • 88
  • 152