What is the syntax of the "for loop" in the linux shell programming?
CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Wed, 16 Jul 2025 21:00:06 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100105190729
location: https://web.archive.org/web/20100105190729/https://answers.oreilly.com/topic/793-shell-programming/
server-timing: captures_list;dur=0.744155, exclusion.robots;dur=0.024978, exclusion.robots.policy;dur=0.011690, esindex;dur=0.016179, cdx.remote;dur=33.798702, LoadShardBlock;dur=312.697794, PetaboxLoader3.datanode;dur=119.451998
x-app-server: wwwb-app220
x-ts: 302
x-tr: 381
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app220; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 301
server: nginx
date: Wed, 16 Jul 2025 21:00:07 GMT
content-type: text/html;charset=UTF-8
content-length: 0
x-archive-orig-date: Tue, 05 Jan 2010 19:07:33 GMT
x-archive-orig-server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
x-archive-orig-x-powered-by: PHP/5.2.8
x-archive-orig-set-cookie: answers_session_id=85243ce3f59543686e4f74896d959076; path=/; domain=.oreilly.com; httponly
x-archive-orig-set-cookie: answers_session_id=85243ce3f59543686e4f74896d959076; path=/; domain=.oreilly.com; httponly
x-archive-orig-cache-control: ,no-cachemust-revalidate, max-age=0
x-archive-orig-expires: 0
x-archive-orig-pragma: no-cache
location: https://web.archive.org/web/20100105190729/https://answers.oreilly.com/topic/793-shell-programming-for-loop/
x-archive-orig-content-length: 0
x-archive-orig-connection: close
cache-control: max-age=1800
memento-datetime: Tue, 05 Jan 2010 19:07:29 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 05 Jan 2010 19:07:29 GMT", ; rel="memento"; datetime="Tue, 05 Jan 2010 19:07:29 GMT", ; rel="next memento"; datetime="Sat, 06 Mar 2010 02:33:45 GMT", ; rel="last memento"; datetime="Sat, 06 Mar 2010 02:33:45 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: TLA-20100105183421-00315-00324-ia360913-20100114113045-00000-c/TLA-20100105184320-00397-ia360906.us.archive.org.warc.gz
server-timing: captures_list;dur=0.852732, exclusion.robots;dur=0.032244, exclusion.robots.policy;dur=0.015857, esindex;dur=0.020456, cdx.remote;dur=24.842996, LoadShardBlock;dur=449.704746, PetaboxLoader3.datanode;dur=87.307803, PetaboxLoader3.resolve;dur=885.324027, load_resource;dur=588.587496
x-app-server: wwwb-app220
x-ts: 301
x-tr: 1102
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 302
server: nginx
date: Wed, 16 Jul 2025 21:00:07 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100105190704
location: https://web.archive.org/web/20100105190704/https://answers.oreilly.com/topic/793-shell-programming-for-loop/
server-timing: captures_list;dur=1.883212, exclusion.robots;dur=0.019556, exclusion.robots.policy;dur=0.010561, esindex;dur=0.011450, cdx.remote;dur=20.418098, LoadShardBlock;dur=139.342377, PetaboxLoader3.datanode;dur=67.711104, PetaboxLoader3.resolve;dur=63.566210
x-app-server: wwwb-app220
x-ts: 302
x-tr: 187
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Wed, 16 Jul 2025 21:00:08 GMT
content-type: text/html;charset=UTF-8
x-archive-orig-date: Tue, 05 Jan 2010 19:07:07 GMT
x-archive-orig-server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8
x-archive-orig-x-powered-by: PHP/5.2.8
x-archive-orig-set-cookie: answers_session_id=85243ce3f59543686e4f74896d959076; path=/; domain=.oreilly.com; httponly
x-archive-orig-set-cookie: answers_session_id=85243ce3f59543686e4f74896d959076; path=/; domain=.oreilly.com; httponly
x-archive-orig-set-cookie: answers_modpids=deleted; expires=Mon, 05-Jan-2009 19:07:07 GMT; path=/; domain=.oreilly.com
x-archive-orig-cache-control: ,no-cachemust-revalidate, max-age=0
x-archive-orig-expires: 0
x-archive-orig-pragma: no-cache
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Tue, 05 Jan 2010 19:07:04 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Wed, 09 Dec 2009 04:32:04 GMT", ; rel="prev memento"; datetime="Wed, 09 Dec 2009 04:32:04 GMT", ; rel="memento"; datetime="Tue, 05 Jan 2010 19:07:04 GMT", ; rel="next memento"; datetime="Wed, 10 Feb 2010 13:10:25 GMT", ; rel="last memento"; datetime="Sat, 02 Nov 2013 18:42:47 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: TLA-20100105183421-00315-00324-ia360913-20100114113045-00000-c/TLA-20100105184320-00397-ia360906.us.archive.org.warc.gz
server-timing: captures_list;dur=1.352476, exclusion.robots;dur=0.056816, exclusion.robots.policy;dur=0.038926, esindex;dur=0.021812, cdx.remote;dur=36.259571, LoadShardBlock;dur=300.896885, PetaboxLoader3.datanode;dur=127.670985, PetaboxLoader3.resolve;dur=244.393339, load_resource;dur=106.795311
x-app-server: wwwb-app220
x-ts: 200
x-tr: 539
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
shell programming for loop - O'Reilly Answers
Welcome
O'Reilly Answers is a community site for sharing knowledge, asking questions, and providing answers that brings together our customers, authors, editors, conference speakers, and Foo (Friends of O'Reilly). More »
Related Questions
Related Posts
Recommended for You
shell programming for loop
1 Answer | 0 Comments
filter by:
For bash:
Use double parenthesis to indicate you want ARITHMETIC EVALUATION (see the bash man page) if you are looking for a traditional C-style loop:
$ for ((i=1; i<10; i++)); do echo $i; done
1
2
3
4
5
6
7
8
9
$
Otherwise use the list type:
$ for ITEM in foo bar baz; do echo $ITEM; done
foo
bar
baz
$
Note: multiple expressions can be entered between the "do" and the "done". Think of the expressions in their more stylized forms if this seems odd (the greater thansymbol in inserted by bash when doing multi-line commands, it is not part of the syntax):
$ for ITEM in foo bar baz
> do
> echo $ITEM
> echo "second part of processing loop"
> done
foo
second part of processing loop
bar
second part of processing loop
baz
second part of processing loop
See "Compound Commands" in the bash man page for more info, and more command structures such as while loops, switch statements, if/then branches, and how to define functions.
Use double parenthesis to indicate you want ARITHMETIC EVALUATION (see the bash man page) if you are looking for a traditional C-style loop:
$ for ((i=1; i<10; i++)); do echo $i; done
1
2
3
4
5
6
7
8
9
$
Otherwise use the list type:
$ for ITEM in foo bar baz; do echo $ITEM; done
foo
bar
baz
$
Note: multiple expressions can be entered between the "do" and the "done". Think of the expressions in their more stylized forms if this seems odd (the greater thansymbol in inserted by bash when doing multi-line commands, it is not part of the syntax):
$ for ITEM in foo bar baz
> do
> echo $ITEM
> echo "second part of processing loop"
> done
foo
second part of processing loop
bar
second part of processing loop
baz
second part of processing loop
See "Compound Commands" in the bash man page for more info, and more command structures such as while loops, switch statements, if/then branches, and how to define functions.
![]() ©2009, O'Reilly Media, Inc. (707) 827-7000 / (800) 998-9938 All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. |
About O'Reilly Academic Solutions Authors Contacts Customer Service Jobs Newsletters O'Reilly Labs Press Room Privacy Policy RSS Feeds Terms of Service User Groups Writing for O'Reilly |
Content Archive Business Technology Computer Technology Microsoft Mobile Network Operating System Digital Photography Programming Software Web Web Design |
More O'Reilly Sites O'Reilly Radar Ignite Tools of Change for Publishing Digital Media Inside iPhone makezine.com craftzine.com hackszine.com perl.com xml.com Partner Sites InsideRIA java.net O'Reilly Insights on Forbes.com |