为什么“ test -e”在我的bash脚本中不能正常工作?

问题描述 投票:-1回答:1

我正在编写一个简短的bash脚本,以查找目录中是否存在文件。这是脚本:

#!/bin/bash

> oldFiles.txt

files=$(grep ' jane ' ../data/list.txt | cut -d ' ' -f 3)

for f in $files; do

f=~$f

if [ -e $f ]; then

  echo $f Found

  echo $f>>oldFiles.txt

else
  echo $f Not found

fi

done

grep找到了三个相关的文件名,并在for循环中搜索了它们。但是,似乎每当我的脚本运行if命令时,无论文件是否存在,它都会返回False。请查看脚本的结果,每个单个文件的后面都是test -e,然后是相关目录中的文件列表。

findJaneResults

我知道我所缺少的很简单,但这是什么?

bash loops scripting sh file-management
1个回答
0
投票

这是重构,有望通过内联注释修复大多数错误。

© www.soinside.com 2019 - 2024. All rights reserved.