【发布时间】:2014-07-11 07:19:46
【问题描述】:
我在无限循环中使用 comm 来查看文件夹中是否有新文件传入,但我与 2 个文件没有区别,但例如,如果 incominig 文件“a”我在输出中查看:
a a.out a.txt b.txt test.cpp testshell.sh
a.out a.txt b.txt test.cpp testshell.sh
我的代码是这样的:
#! /bin/ksh
ls1=$(ls);
echo $ls1 > a.txt;
while [[ 1 > 0 ]] ; do
ls2=$(ls);
echo $ls2 > b.txt;
#cat b.txt;
#sort b.txt > b.txt;
#diff -u a.txt b.txt;
#diff -a --suppress-common-lines -y a.txt b.txt
comm -3 a.txt b.txt;
printf "\n";
ls1=$ls2;
echo $ls1 > a.txt;
#cat a.txt;
#sleep 2;
#sort a.txt > a.txt;
done
谢谢
【问题讨论】:
-
当您将变量回显到文件中时,它们需要被双引号以保留换行符 - 例如
echo "$ls1" > a.txt
标签: shell command-line ksh