Bash for: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * bash")
 
No edit summary
Line 2: Line 2:


* [[bash#Built-In_Commands|bash]]
* [[bash#Built-In_Commands|bash]]
!!!bash for
!!!Internal
|[bash]
!!!Overview
{{{
   
    for i in words; do commands; done
}}}
If the keyword "in" is not present, {{for}} will iterate through positional parameters.
Alternative form:
{{{
    for (( i=0; i<${#names[@]}; i++ )); do
        local name=${names[${i}]}
        echo "${name}"
    done
}}}
!!!Iterating through $1, $2, $3 ...
{{{
    for i do
        echo ${i}
    done
}}}
!!!Iterating through a space separated list
{{{
    s="a b c"
    for i in ${s}
        do
            echo ${i}
        done
}}}
or
{{{
    s="a b c"
    for i in ${s}; do echo ${i}; done
}}}
Note the use of ";"
__Referenced by:__\\
[{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=20, maxwidth=50}]

Revision as of 23:41, 29 February 2016

Internal



!!!bash for


!!!Internal

|[bash]


!!!Overview

{{{

   for i in words; do commands; done

}}}

If the keyword "in" is not present, Template:For will iterate through positional parameters.

Alternative form:

{{{

   for (( i=0; i<${#names[@]}; i++ )); do
       local name=${names[${i}]}
       echo "${name}"
   done

}}}

!!!Iterating through $1, $2, $3 ...

{{{

    for i do
        echo ${i}
    done

}}}

!!!Iterating through a space separated list


{{{

   s="a b c"
   for i in ${s}
       do
           echo ${i}
       done

}}}

or

{{{

    s="a b c"
    for i in ${s}; do echo ${i}; done

}}}

Note the use of ";"


__Referenced by:__\\ [{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=20, maxwidth=50}]