开发者

pipe into conditional on command line

I have a problem i cou开发者_Go百科ld not figure out if it's even possible. I am parsing a file with filenames in it, and want to check if those filenames represent an existing file within the system.

i figured out a possibility to to check if a file exists:

 [ -f FILENAME ] && echo "File exists" || echo "File does not exists"

now my problem is: How can i pipe into to the conditional that it tests for all the filenames?

i was trying like tihs, but it did not work:

cat myfilenames.txt | xargs command from above without FILENAME

does anybody know if it is possible?

thanks, dmeu!


while read file; dp
        [ -e "$file" ] && echo "$file exists";
done <filelist.txt


I believe what you want is a for loop. This worked for me in bash (I put it in a shell script, but you could probably do it on the command line):

for i in  `cat $1` ; do
    [ -f $i ] && echo File $i exists || echo File $i does not exist 
done

the backticks around the cat execute the command and substitute the output into the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜