首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >$f在shell脚本中意味着什么?

$f在shell脚本中意味着什么?
EN

Stack Overflow用户
提问于 2015-12-04 05:00:29
回答 2查看 11.1K关注 0票数 0
代码语言:javascript
运行
复制
#!/bin/bash
Files=`(find .  -type f)`
 for f in $Files
 do
  if [ "$(dirname $f)" != "." ]
  then
  # these are files in a subdirectory
   x=$(dirname $f)  #get the name of the file with the directory
   y=${x:2}         #remove ./ from the name
   echo $(basename $f) \($y\)
  else
   # these are files in the current directory
   echo $(basename $f)
 fi
done

我很难理解这句话的意思

代码语言:javascript
运行
复制
Files=1(find . -type f)` 

意思是?它是否找到目录中的每个文件?“类型f”是否意味着查找每个“文件”类型?另外,$f的功能是什么?

我是从壳牌开始的,所以任何帮助都会很有帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-04 05:04:17

for f in $Files..。$f引用该for循环变量。它也可以写成

代码语言:javascript
运行
复制
Files=`(find .  -type f)`
for fred in $Files
do
  if [ "$(dirname $fred)" != "." ]
  then
  # these are files in a subdirectory
   x=$(dirname $fred)  #get the name of the file with the directory
   y=${x:2}         #remove ./ from the name
   echo $(basename $fred) \($y\)
  else
   # these are files in the current directory
   echo $(basename $fred)
 fi
done

是的,-type f的意思是“文件”。

票数 3
EN

Stack Overflow用户

发布于 2015-12-04 06:43:03

对不起,我还没有足够的声誉来发表评论。埃利奥特对你的“f”变量名有正确的答案。不过,要回答您的后续问题,期间的重要性与文件类型无关。

在linux中,“.”表示您的pwd或当前工作目录。pwd的父目录由“..”表示。find命令要求提供路径,无论是相对路径还是绝对路径。“.”实现这一目标的有效方法是:“在当前目录(.)和所有子目录中搜索”。查找是自然递归的IIRC。

黑客行动愉快!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34081194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档