for
rose1 发表于 2020-09-17 09:03浏览次数:
在类似Unix的操作系统上,for命令是一个shell命令,该命令执行循环,多次重复一个动作或一组动作。
本文档介绍了for的bash 内置版本。
On Unix-like operating systems, the for command is a shell command which performs a loop, iterating an action or set of actions many times.
This document covers the bash built-in version of for.
目录:
1 for 运行系统环境
2 for 说明
3 for 语法
4 for 例子
for 运行系统环境
for 说明
将用于表明是一个for循环。一个用于循环是一种编程语言 的语句,它允许被重复执行的代码。与其他类型的循环(如while循环)不同,for循环通常在进入循环之前已知迭代次数时使用。
上面的语法描述了如何在Linux / Unix中使用for循环,该循环可以在命令行中或在Shell 脚本中执行。
The for keyword indicates a for loop. A for loop is a programming language statement that allows code to be repeatedly executed. Unlike other types of loops, such as the while loop, for loops are often used when the number of iterations is known before entering the loop.
The syntax above describes how to use a for loop in Linux/Unix which can be executed at the command line or inside a shell script.
for 语法
for WORD [ in WORDLIST ... ] ; do ACTIONS ; done
for WORD [ in WORDLIST ... ] ; do ACTIONS ; done
for 例子
for file in *.txt ; do wc -l $file ; done
执行字数在当前的所有文件的目录与扩展名为.txt,并将结果返回类似如下:
5 myfile.txt
2 myfile2.txt
14 newfile.txt
for file in *.txt ; do wc -l $file ; done
Performs a word count of all files in the current directory with the extension .txt, and returns results similar to the following:
5 myfile.txt
2 myfile2.txt
14 newfile.txt