qwe*_*ymk 10 bash shell for-loop
我有一个类似于以下内容的bash脚本:
#!/bin/bash
FILES=public_html/*.php # */ stupid syntax highlighter!
for f in $FILES
do
echo "Processing $f file..."
# take action on each file.
done
Run Code Online (Sandbox Code Playgroud)
现在我需要它来遍历所有子目录,public_html
所以它应该运行:
/public_html/index.php
/public_html/forums/status.php
/public_html/really/deep/file/in/many/sub/dirs/here.php
Run Code Online (Sandbox Code Playgroud)
FILES=public_html/*.php
为了做到这一点,我该改变什么?
此外,我需要检查以确保至少有一个文件或打印
Processing *.php file...
Run Code Online (Sandbox Code Playgroud)
sgi*_*ibb 30
FILES=$(find public_html -type f -name '*.php')
Run Code Online (Sandbox Code Playgroud)
重要提示:请注意周围的单引号*.php
以防止shell扩展*
.