简体   繁体   English

Bash 脚本 - 在 for 循环中使用 if

[英]Bash scripting - using if in a for loop

I am total noob in bash scripting and do not know what the problem is within my code;我在 bash 脚本方面完全是个菜鸟,不知道我的代码有什么问题; I am writing an sh extension file that will be used as a buffer into the Linux sys.我正在编写一个 sh 扩展文件,该文件将用作 Linux 系统的缓冲区。 This is just a practice but I do not know what the problem within the code really is, can someone tell me?这只是一个练习,但我不知道代码中的问题到底是什么,有人可以告诉我吗?

Thanks谢谢

在此处输入图片说明

This is the answer I came up with in the end这是我最后想出的答案

#!/bin/bash
>oldFiles.txt
files=$(grep ' jane ' ../data/list.txt | cut -d ' ' -f 3)
for x in $files;
do 
    if test -e ../data/$x; then echo $x >> oldFiles.txt; else echo $x; fi;
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM