Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无参数的Bash for循环_Bash - Fatal编程技术网

无参数的Bash for循环

无参数的Bash for循环,bash,Bash,有人能解释一下为什么下面的代码在bash中是有效的,如果有的话,效果如何 表示值;做 echo美元价值 完成 据我所知,bash只是忽略了这段代码,但我不明白为什么它不会引发语法错误或其他什么?正如@Jetchisel所指出的,我们可以在shell中运行help for,查看for命令的docstring $ help for for: for NAME [in WORDS ... ] ; do COMMANDS; done Execute commands for each memb

有人能解释一下为什么下面的代码在bash中是有效的,如果有的话,效果如何

表示值;做
echo美元价值
完成

据我所知,bash只是忽略了这段代码,但我不明白为什么它不会引发语法错误或其他什么?

正如@Jetchisel所指出的,我们可以在shell中运行
help for
,查看
for
命令的docstring

$ help for
for: for NAME [in WORDS ... ] ; do COMMANDS; done
    Execute commands for each member in a list.
    
    The `for' loop executes a sequence of commands for each member in a
    list of items.  If `in WORDS ...;' is not present, then `in "$@"' is
    assumed.  For each element in WORDS, NAME is set to that element, and
    the COMMANDS are executed.
    
    Exit Status:
    Returns the status of the last command executed.
我不知道的部分强调如下:

[…]如果`用词…;'不存在,则假定为“$@”中的“in”。[…]


在终端中运行的帮助,尝试验证shell脚本。谢谢!你能加上这个作为答案吗?这样我就可以接受了。没关系,我把它留在这里。