ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 3.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s05.html |
| Last Crawled | 2026-01-05 00:38:42 (3 months ago) |
| First Indexed | 2019-02-15 13:41:04 (7 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Looping around with for - Linux Shell Scripting Essentials [Book] |
| Meta Description | Looping around with forThe for loop can be used to iterate over the items in a list or till the condition is true.The syntax of using the for loop in bash is as follows:for item in... - Selection from Linux Shell Scripting Essentials [Book] |
| Meta Canonical | null |
| Boilerpipe Text | November 2015
Beginner
282 pages
5h 5m
English
Content preview from
Linux Shell Scripting Essentials
Looping around with for
The
for
loop can be used to iterate over the items in a list or till the condition is true.
The syntax of using the
for
loop in bash is as follows:
for item in [list]
do
#Tasks
done
Another way of writing the
for
loop is the way C does, as follows:
for (( expr1; expr2; expr3 ))
# Tasks
done
Here,
expr1
is initialization,
expr2
is condition, and
expr3
is increment.
Simple iteration
The following shell script explains how we can use the
for
loop to print the values of a list:
#!/bin/bash
# Filename: for_loop.sh
# Description: Basic for loop in bash
declare -a names=(Foo Bar Tom Jerry)
echo "Content of names array is:"
for name in ${names[@]}
do
echo -n "$name "
done
echo
The output of the script is as follows:
Content of names array ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like |
| Markdown | [Skip to Content](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s05.html#main)
- [For Enterprise](https://www.oreilly.com/online-learning/teams.html)
- [For Government](https://www.oreilly.com/online-learning/government.html)
- [For Higher Ed](https://www.oreilly.com/online-learning/academic.html)
- [For Individuals](https://www.oreilly.com/online-learning/individuals.html)
- [For Marketing](https://www.oreilly.com/content-marketing-solutions.html)
[](https://www.oreilly.com/ "home page")
- - [For Enterprise](https://www.oreilly.com/online-learning/teams.html)
- [For Government](https://www.oreilly.com/online-learning/government.html)
- [For Higher Ed](https://www.oreilly.com/online-learning/academic.html)
- [For Individuals](https://www.oreilly.com/online-learning/individuals.html)
- [For Marketing](https://www.oreilly.com/content-marketing-solutions.html)
- [Explore Skills](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s05.html)
- [Cloud Computing](https://www.oreilly.com/search/skills/cloud-computing/)
- [Microsoft Azure](https://www.oreilly.com/search/skills/microsoft-azure/)
- [Amazon Web Services (AWS)](https://www.oreilly.com/search/skills/amazon-web-services-aws/)
- [Google Cloud](https://www.oreilly.com/search/skills/google-cloud/)
- [Cloud Migration](https://www.oreilly.com/search/skills/cloud-migration/)
- [Cloud Deployment](https://www.oreilly.com/search/skills/cloud-deployment/)
- [Cloud Platforms](https://www.oreilly.com/search/skills/cloud-platforms/)
- [Data Engineering](https://www.oreilly.com/search/skills/data-engineering/)
- [Data Warehouse](https://www.oreilly.com/search/skills/data-warehouse/)
- [SQL](https://www.oreilly.com/search/skills/sql/)
- [Apache Spark](https://www.oreilly.com/search/skills/apache-spark/)
- [Microsoft SQL Server](https://www.oreilly.com/search/skills/microsoft-sql-server/)
- [MySQL](https://www.oreilly.com/search/skills/mysql/)
- [Kafka](https://www.oreilly.com/search/skills/kafka/)
- [Data Lake](https://www.oreilly.com/search/skills/data-lake/)
- [Streaming & Messaging](https://www.oreilly.com/search/skills/streaming-messaging/)
- [NoSQL Databases](https://www.oreilly.com/search/skills/nosql-databases/)
- [Relational Databases](https://www.oreilly.com/search/skills/relational-databases/)
- [Data Science](https://www.oreilly.com/search/skills/data-science/)
- [Pandas](https://www.oreilly.com/search/topics/pandas/)
- [R](https://www.oreilly.com/search/topics/r/)
- [MATLAB](https://www.oreilly.com/search/topics/matlab/)
- [SAS](https://www.oreilly.com/search/topics/sas/)
- [D3](https://www.oreilly.com/search/topics/d3/)
- [Power BI](https://www.oreilly.com/search/topics/power-bi/)
- [Tableau](https://www.oreilly.com/search/topics/tableau/)
- [Statistics](https://www.oreilly.com/search/topics/statistics/)
- [Exploratory Data Analysis](https://www.oreilly.com/search/topics/exploratory-data-analysis/)
- [Data Visualization](https://www.oreilly.com/search/topics/data-visualization/)
- [AI & ML](https://www.oreilly.com/search/skills/ai-ml/)
- [Generative AI](https://www.oreilly.com/search/skills/generative-ai/)
- [Machine Learning](https://www.oreilly.com/search/skills/machine-learning/)
- [Artificial Intelligence (AI)](https://www.oreilly.com/search/skills/artificial-intelligence-ai/)
- [Deep Learning](https://www.oreilly.com/search/skills/deep-learning/)
- [Reinforcement Learning](https://www.oreilly.com/search/skills/reinforcement-learning/)
- [Natural Language Processing](https://www.oreilly.com/search/skills/natural-language-processing/)
- [TensorFlow](https://www.oreilly.com/search/skills/tensorflow/)
- [Scikit-Learn](https://www.oreilly.com/search/skills/scikit-learn/)
- [Hyperparameter Tuning](https://www.oreilly.com/search/skills/hyperparameter-tuning/)
- [MLOps](https://www.oreilly.com/search/skills/mlops/)
- [Programming Languages](https://www.oreilly.com/search/skills/programming-languages/)
- [Java](https://www.oreilly.com/search/skills/java/)
- [JavaScript](https://www.oreilly.com/search/skills/javascript/)
- [Spring](https://www.oreilly.com/search/skills/spring/)
- [Python](https://www.oreilly.com/search/skills/python/)
- [Go](https://www.oreilly.com/search/skills/go/)
- [C\#](https://www.oreilly.com/search/skills/c-sharp/)
- [C++](https://www.oreilly.com/search/skills/c-plus-plus/)
- [C](https://www.oreilly.com/search/skills/c/)
- [Swift](https://www.oreilly.com/search/skills/swift/)
- [Rust](https://www.oreilly.com/search/skills/rust/)
- [Functional Programming](https://www.oreilly.com/search/skills/functional-programming/)
- [Software Architecture](https://www.oreilly.com/search/skills/software-architecture/)
- [Object-Oriented](https://www.oreilly.com/search/skills/object-oriented-architecture/)
- [Distributed Systems](https://www.oreilly.com/search/skills/distributed-systems/)
- [Domain-Driven Design](https://www.oreilly.com/search/skills/domain-driven-design/)
- [Architectural Patterns](https://www.oreilly.com/search/skills/architectural-patterns/)
- [IT/Ops](https://www.oreilly.com/search/skills/it-operations/)
- [Kubernetes](https://www.oreilly.com/search/topics/kubernetes/)
- [Docker](https://www.oreilly.com/search/topics/docker/)
- [GitHub](https://www.oreilly.com/search/topics/github/)
- [Terraform](https://www.oreilly.com/search/topics/terraform/)
- [Continuous Delivery](https://www.oreilly.com/search/topics/continuous-delivery/)
- [Continuous Integration](https://www.oreilly.com/search/topics/continuous-integration/)
- [Database Administration](https://www.oreilly.com/search/topics/database-administration/)
- [Computer Networking](https://www.oreilly.com/search/topics/computer-networking/)
- [Operating Systems](https://www.oreilly.com/search/topics/operating-systems/)
- [IT Certifications](https://www.oreilly.com/search/topics/it-certifications/)
- [Security](https://www.oreilly.com/search/skills/security/)
- [Network Security](https://www.oreilly.com/search/skills/network-security/)
- [Application Security](https://www.oreilly.com/search/skills/application-security/)
- [Incident Response](https://www.oreilly.com/search/skills/incident-response/)
- [Zero Trust Model](https://www.oreilly.com/search/skills/zero-trust-model/)
- [Disaster Recovery](https://www.oreilly.com/search/skills/disaster-recovery/)
- [Penetration Testing / Ethical Hacking](https://www.oreilly.com/search/skills/penetration-testing-ethical-hacking/)
- [Governance](https://www.oreilly.com/search/skills/governance/)
- [Malware](https://www.oreilly.com/search/skills/malware/)
- [Security Architecture](https://www.oreilly.com/search/skills/security-architecture/)
- [Security Engineering](https://www.oreilly.com/search/skills/security-engineering/)
- [Security Certifications](https://www.oreilly.com/search/skills/security-certifications/)
- [Design](https://www.oreilly.com/search/skills/design/)
- [Web Design](https://www.oreilly.com/search/skills/web-design/)
- [Graphic Design](https://www.oreilly.com/search/skills/graphic-design/)
- [Interaction Design](https://www.oreilly.com/search/skills/interaction-design/)
- [Film & Video](https://www.oreilly.com/search/skills/film-video/)
- [User Experience (UX)](https://www.oreilly.com/search/skills/user-experience-ux/)
- [Design Process](https://www.oreilly.com/search/skills/design-process/)
- [Design Tools](https://www.oreilly.com/search/skills/design-tools/)
- [Business](https://www.oreilly.com/search/skills/business/)
- [Agile](https://www.oreilly.com/search/skills/agile/)
- [Project Management](https://www.oreilly.com/search/skills/project-management/)
- [Product Management](https://www.oreilly.com/search/skills/product-management/)
- [Marketing](https://www.oreilly.com/search/skills/marketing/)
- [Human Resources](https://www.oreilly.com/search/skills/human-resources/)
- [Finance](https://www.oreilly.com/search/skills/finance/)
- [Team Management](https://www.oreilly.com/search/skills/team-management/)
- [Business Strategy](https://www.oreilly.com/search/skills/business-strategy/)
- [Digital Transformation](https://www.oreilly.com/search/skills/digital-transformation/)
- [Organizational Leadership](https://www.oreilly.com/search/skills/organizational-leadership/)
- [Soft Skills](https://www.oreilly.com/search/skills/soft-skills/)
- [Professional Communication](https://www.oreilly.com/search/skills/professional-communication/)
- [Emotional Intelligence](https://www.oreilly.com/search/skills/emotional-intelligence/)
- [Presentation Skills](https://www.oreilly.com/search/skills/presentation-skills/)
- [Innovation](https://www.oreilly.com/search/skills/innovation/)
- [Critical Thinking](https://www.oreilly.com/search/skills/critical-thinking/)
- [Public Speaking](https://www.oreilly.com/search/skills/public-speaking/)
- [Collaboration](https://www.oreilly.com/search/skills/collaboration/)
- [Personal Productivity](https://www.oreilly.com/search/skills/personal-productivity/)
- [Confidence / Motivation](https://www.oreilly.com/search/skills/confidence-motivation/)
- [Features](https://www.oreilly.com/online-learning/features.html)
- [All features](https://www.oreilly.com/online-learning/features.html)
- [Verifiable skills](https://www.oreilly.com/online-learning/verifiable-skills.html)
- [AI Academy](https://www.oreilly.com/online-learning/ai-academy.html)
- [Courses](https://www.oreilly.com/online-learning/courses.html)
- [Certifications](https://www.oreilly.com/online-learning/feature-certification.html)
- [Interactive learning](https://www.oreilly.com/online-learning/intro-interactive-learning.html)
- [Live events](https://www.oreilly.com/online-learning/live-events.html)
- [Superstreams](https://www.oreilly.com/products/superstreams.html)
- [Answers](https://www.oreilly.com/online-learning/feature-answers.html)
- [Insights reporting](https://www.oreilly.com/online-learning/insights-dashboard.html)
- [Radar Blog](https://www.oreilly.com/radar/)
- [Buy Courses](https://www.oreilly.com/live/)
- - [Plans](https://www.oreilly.com/online-learning/pricing.html)
- [Sign In](https://www.oreilly.com/member/login/)
- [Try Now](https://www.oreilly.com/online-learning/try-now.html)
- [O'Reilly Platform](https://www.oreilly.com/member/login/)

book
# Linux Shell Scripting Essentials
##### by [Sinny Kumari](https://www.oreilly.com/search/?query=author:"Sinny%20Kumari"&sort=relevance&highlight=true)
November 2015
Beginner
282 pages
5h 5m
English
[Packt Publishing](https://www.oreilly.com/publisher/dd0773f2-2d09-4827-9191-33477b14398c/)
[Read nowUnlock full access](https://www.oreilly.com/start-trial/?next=/library/view/linux-shell-scripting/9781785284441/ch03s05.html)
### Contents
- ### [Linux Shell Scripting Essentials](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/index.html)
- ### [Table of Contents](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/toc.html)
- ### [Linux Shell Scripting Essentials](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr01.html)
- ### [Credits](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr02.html)
- ### [About the Author](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr03.html)
- ### [About the Reviewers](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr04.html)
- ### [www.PacktPub.com](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr05.html)
Support files, eBooks, discount offers, and moreWhy subscribe?Free access for Packt account holders
- ### [Preface](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06.html)
What this book covers
- ### [What you need for this book](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06s02.html)
- ### [Who this book is for](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06s03.html)
- ### [Conventions](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06s04.html)
- ### [Reader feedback](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06s05.html)
- ### [Customer support](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/pr06s06.html)
Downloading the example codeErrataPiracyQuestions
- ### [1\. The Beginning of the Scripting Journey](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01.html)
Hello World in shellInteracting with shellLet's make it scripted
- ### [Define variables of choice](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s02.html)
NomenclatureAssigning a valueAccessing a valueConstant variablesReading variables from a user input
- ### [Builtin shell variables](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s03.html)
- ### [Operators](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s04.html)
The assignment operatorArithmetic operatorsLogical operatorsComparison operators
- ### [Shell expansions](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s05.html)
~ (Tilde)\* (Asterisk)? (Question mark)\[ \] (Square brackets){ } (Curly brackets)
- ### [Construct commands using eval](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s06.html)
- ### [Make bash behave using set](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s07.html)
Exit on the first failureEnabling/disabling symbolic link's resolution pathSetting/unsetting variables
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch01s08.html)
- ### [2\. Getting Hands-on with I/O, Redirection Pipes, and Filters](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02.html)
Standard I/O and error streamsFile descriptors
- ### [Redirecting the standard I/O and error streams](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s02.html)
Redirecting standard outputRedirecting standard inputRedirecting standard errorsMultiple redirection
- ### [Pipe and pipelines – connecting commands](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s03.html)
PipePipeline
- ### [Regular expressions](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s04.html)
Regular expression metacharactersCharacter ranges and classesCharacter rangesMatching dates in mm-dd-yyyy formatMatching a valid monthMatching a valid dayMatching the valid year in a dateCombining valid months, days, and years regex to form valid datesRegex for a valid shell variable
- ### [Filtering an output using grep](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s05.html)
SyntaxLooking for a pattern in a fileLooking for a pattern in multiple filesA few more grep usagesSearching in a binary fileSearching in a directoryExcluding files/directories from a searchDisplay a filename with a matching patternMatching an exact word
- ### [Editing output using sed](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s06.html)
String substitution using sMultiple substitutions
- ### [Duplicating a stream using tee](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s07.html)
Writing an output to stdout and appending to a fileSending an output to multiple commands
- ### [Sorting and finding unique text](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s08.html)
Sorting an input textSorting a single fileRedirecting output to sortFiltering unique elementsUnique elements in a file
- ### [Character-based translation using tr](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s09.html)
Deleting input charactersSqueezing to a single occurrenceInverting a character set to be translated
- ### [Filtering based on lines—head and tail](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s10.html)
Printing lines using headPrinting the first few linesPrinting the first few bytesPrinting lines using tailChecking log entriesFinding any line in a file
- ### [The Cut-based selection](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s11.html)
Cutting across columnsText selection in files
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch02s12.html)
- ### [3\. Effective Script Writing](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03.html)
Exiting from scripts and exit codesExit codesExit codes with a special meaningScript with exit codes
- ### [Testing expressions with a test](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s02.html)
File checksArithmetic checksString checksExpression checks
- ### [Using conditional statements with if and else](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s03.html)
Simple if and elseThe if, elif, and else statementsNested if
- ### [Indexed arrays and associative arrays](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s04.html)
Indexed arraysArray declaration and value assignmentOperations on arraysThe associative arrayThe declaration and value assignmentOperations on arrays
- ### [Looping around with for](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s05.html)
Simple iterationIterating over a command outputSpecifying a range to the for loopSmall and sweet for loop
- ### [The select, while, and until loops](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s06.html)
Loop using selectThe while loopThe until loop
- ### [Switch to my choice](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s07.html)
- ### [Passing stdout as a parameter using xargs](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s08.html)
Basic operations with xargsUsing xargs to find a file with the maximum sizeArchiving files with a given pattern
- ### [Using functions and positional parameters](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s09.html)
Calling a function in bashPassing parameters to functions
- ### [Alias](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s10.html)
Creating aliasListing all aliasesRemoving an alias
- ### [pushd and popd](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s11.html)
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s12.html)
- ### [4\. Modularizing and Debugging](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch04.html)
Modularizing your scriptsSource to a script fileSyntaxCreating a shell script libraryLoading a shell script libraryCalling a shell library in bashCalling shell library in another shell script
- ### [Passing command line parameters to script](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch04s02.html)
Reading arguments in scriptsShifting command line argumentsProcessing command line options in a script
- ### [Debugging your scripts](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch04s03.html)
Debugging using echoDebugging an entire script using -xDebugging sections of a script using the set options
- ### [Command completion](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch04s04.html)
Managing bash completion with completeViewing the existing bash completionModifying default bash completion behaviorRemoving bash completion specificationWriting bash completion for your own applicationAn example of bash completionRunning the created bash completion
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch04s05.html)
- ### [5\. Customizing the Environment](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05.html)
Knowing the default environmentViewing a shell environmentprintenvenvDifferences between shell and environment variables
- ### [Modifying a shell environment](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05s02.html)
Creating environment variablesModifying environment variablesDeleting environment variables
- ### [Using bash startup files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05s03.html)
.bashrc.bash\_profile.bash\_logout
- ### [Knowing your history](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05s04.html)
Shell variables controlling the historyThe history builtin commandModifying the default history behaviorHandy shortcuts for seeing the history\[Ctrl + r\]Up and down arrow key!\!!(search\_string)!?(search\_string)
- ### [Task management](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05s05.html)
Running tasks in the backgroundSending a running task to the backgroundListing background tasksMoving tasks to the foregroundTerminating tasks
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch05s06.html)
- ### [6\. Working with Files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06.html)
Performing basic file operationsCreating filesDirectory fileRegular fileTouch commandUsing the command line editorsUsing the cat commandRedirecting the command's outputModifying filesViewing filesViewing content using catmore and lessDeleting filesDeleting a regular fileDeleting a directory
- ### [Moving and copying files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s02.html)
Moving filesMoving a directory to a new locationRenaming a fileCopying filesCopying files locallyCopying a file to another locationCopying files remotelyCopying files to a remote server
- ### [Comparing files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s03.html)
Files comparison using diffExample
- ### [Finding files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s04.html)
Searching files according to use caseFinding and deleting a file based on inode number
- ### [Links to a file](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s05.html)
Soft linkHard linkDifference between hard link and soft link
- ### [Special files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s06.html)
The block device fileNamed pipe fileSocket file
- ### [Temporary files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s07.html)
Creating a temporary file using mktemp
- ### [Permission and ownership](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s08.html)
Viewing the ownership and permission of filesChanging permissionChanging the owner and groupChanging a file's ownerChanging group ownership
- ### [Getting the list of open files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s09.html)
Knowing the files opened by a specific applicationListing the applications that opened a fileKnowing the files opened by a user
- ### [Configuration files](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s10.html)
Viewing and modifying configuration files
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch06s11.html)
- ### [7\. Welcome to the Processes](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07.html)
Process managementProcess creation and executionProcess terminationUsing the kill commandUsing the killall commandUsing the pkill command
- ### [Listing and monitoring processes](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s02.html)
Listing processesSyntaxSimple process selectionProcess selection by listOutput format controlListing all processes with detailsListing all processes run by a userProcesses running in the current terminalListing processes by a command nameTree format display of processesMonitoring processes
- ### [Process substitution](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s03.html)
Diffing the output of two processes
- ### [Process scheduling priorities](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s04.html)
Changing scheduling prioritiesUsing niceUsing renice
- ### [Signals](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s05.html)
Available signals
- ### [Traps](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s06.html)
- ### [Inter-process communication](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s07.html)
Information on IPC using ipcsListing information provided by IPCsKnowing processes' PID who recently did IPCs
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch07s08.html)
- ### [8\. Scheduling Tasks and Embedding Languages in Scripts](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08.html)
Running tasks at a specific timeExecuting scripts using atScheduling commandsScheduling a script fileListing scheduled tasksRemoving scheduled tasks
- ### [Cron jobs](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08s02.html)
Cron daemonCron configurationCrontab entriesSpecial strings in Crontab
- ### [Managing the crontab entry](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08s03.html)
Listing crontab entriesEditing crontab entriesRemoving crontab entries
- ### [systemd](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08s04.html)
systemd unitsManaging servicesStatus of a serviceEnabling and disabling servicesStart and stop a serviceViewing system logsViewing the latest log entriesViewing logs of a particular time interval
- ### [Embedding languages](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08s05.html)
Embedding Python languageEmbedding AWK language
- ### [Summary](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch08s06.html)
- ### [Index](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/backindex.html)
Show More
Content preview from [Linux Shell Scripting Essentials](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/)
# Looping around with for
The `for` loop can be used to iterate over the items in a list or till the condition is true.
The syntax of using the `for` loop in bash is as follows:
```
for item in [list]
do
#Tasks
done
```
Another way of writing the `for` loop is the way C does, as follows:
```
for (( expr1; expr2; expr3 ))
# Tasks
done
```
Here, `expr1` is initialization, `expr2` is condition, and `expr3` is increment.
## Simple iteration
The following shell script explains how we can use the `for` loop to print the values of a list:
```
#!/bin/bash
# Filename: for_loop.sh
# Description: Basic for loop in bash
declare -a names=(Foo Bar Tom Jerry)
echo "Content of names array is:"
for name in ${names[@]}
do
echo -n "$name "
done
echo
```
The output of the script is as follows:
```
Content of names array ...
```
##### Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
[Start your free trial](https://www.oreilly.com/start-trial/?next=/library/view/linux-shell-scripting/9781785284441/ch03s05.html)
### You might also like
[](https://www.oreilly.com/library/view/-/9781785286216/)
[Learning Linux Shell Scripting](https://www.oreilly.com/library/view/-/9781785286216/)
Ganesh Sanjiv Naik
[](https://www.oreilly.com/library/view/-/9781788990554/)
[Mastering Linux Shell Scripting - Second Edition](https://www.oreilly.com/library/view/-/9781788990554/)
Mokhtar Ebrahim, Andrew Mallett
[](https://www.oreilly.com/library/view/-/9781785881985/)
[Linux Shell Scripting Cookbook - Third Edition](https://www.oreilly.com/library/view/-/9781785881985/)
Clif Flynt, Sarath Lakshman, Shantanu Tushar
[](https://www.oreilly.com/library/view/-/9781788995597/)
[Learn Linux Shell Scripting - Fundamentals of Bash 4.4](https://www.oreilly.com/library/view/-/9781788995597/)
Sebastiaan Tammer
### Publisher Resources
ISBN: 9781785284441[Supplemental Content](https://downloads.packtpub.com/code/9781785284441.zip)
Follow us
## [About O'Reilly](https://www.oreilly.com/about/)
- [Teach/Write/Train](https://www.oreilly.com/work-with-us.html)
- [Careers](https://www.oreilly.com/careers/)
- [O'Reilly News](https://www.oreilly.com/press/)
- [Media Coverage](https://www.oreilly.com/press/media-coverage.html)
- [Community Partners](https://www.oreilly.com/partner/signup.csp)
- [Affiliate Program](https://www.oreilly.com/affiliates/)
- [Submit an RFP](https://www.oreilly.com/online-learning/rfp.html)
- [Diversity](https://www.oreilly.com/diversity/)
- [Content Sponsorship](https://www.oreilly.com/content-marketing-solutions.html)
## [Support](https://www.oreilly.com/online-learning/support/)
- [Contact Us](https://www.oreilly.com/about/contact.html)
- [Newsletters](https://www.oreilly.com/emails/newsletters/)
- [Privacy Policy](https://www.oreilly.com/privacy.html)
- [AI Policy](https://www.oreilly.com/about/oreilly-approach-to-generative-ai.html)
## [International](https://www.oreilly.com/library/view/linux-shell-scripting/9781785284441/ch03s05.html)
- [Australia & New Zealand](https://www.oreilly.com/online-learning/anz.html)
- [Japan](https://www.oreilly.co.jp/index.shtml)
## Download the O'Reilly App
Take O'Reilly with you and learn anywhere, anytime on your phone and tablet.
- [](https://itunes.apple.com/us/app/safari-to-go/id881697395 "Download in the Apple App Store")
- [](https://play.google.com/store/apps/details?id=com.safariflow.queue)
## Watch on Your Big Screen
View all O'Reilly videos, virtual conferences, and live events on your home TV.
- [](https://channelstore.roku.com/details/c9d25fa651f0ad84e484b0dfd4b20172:856a240ad268961983e91ae52c1e1e5c/oreilly "O'Reilly on Roku")
- [](https://www.amazon.com/OReilly-Media-Inc/dp/B087YYHL5C/ref=sr_1_2?dchild=1&keywords=oreilly&qid=1604964116&s=mobile-apps&sr=1-2 "O'Reilly on Amazon Fire TV")
[](https://www.oreilly.com/ "home page")
[Do not sell or share my personal information](https://www.oreilly.com/privacy.html?donotsell=show).
© 2025, O'Reilly Media, Inc. All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
- [Terms of Service](https://www.oreilly.com/terms/)
- [Privacy Policy](https://www.oreilly.com/privacy)
- [Editorial Independence](https://www.oreilly.com/about/editorial_independence.html)
- [Modern Slavery Act Statement](https://www.oreilly.com/modern-slavery-act-transparency-statement.html) |
| Readable Markdown | null |
| Shard | 115 (laksa) |
| Root Hash | 3309313061461398115 |
| Unparsed URL | com,oreilly!www,/library/view/linux-shell-scripting/9781785284441/ch03s05.html s443 |