0

我正在开发一个 bash 脚本,以在基于 debian 的系统中每天存储包的差异。

我正在玩弄下面的代码以降低功能,然后再对其进行微调并遇到问题

comm -1 -3  $DIR/$TODAY  $DIR/$PREV  > pkgs.log

当我对文件名进行硬编码并且 pkg.log 包含两者之间的差异时,这似乎是变量的问题。使用 diff 命令时,变量按预期工作,所以我不确定确切的原因是什么。

#directory where lists will reside
DIR=".pkgLists"

#create package dir if it does not exist
if [ ! -d $DIR ]; then
        mkdir $DIR
fi

#previous list of packages  
#this needs to be updated
#for now it serves for testing purposes
PREV="$(ls -1t $DIR | head -n 1)"

#get todays date , it will be used for the file name
TODAY="$(date +%d-%m-%y)_installed_pkgs.list"



#get installed packeges and write sorted output to file
dpkg --get-selections | sort > $DIR/$TODAY


#check the difference between todays file and the previous ones 

# this command works fine when I hardcode the names but not with the variables
# which work fine with the diff command below
# pkgs.log is always empty when I use the variables
comm -1 -3  $DIR/$TODAY  $DIR/$PREV  > pkgs.log

#this command works with the variables
# pkgs2.log always contains the expected information
diff  $DIR/$TODAY $DIR/$PREV  > pkgs2.log

如果有人可以提供帮助,我将不胜感激。

4

0 回答 0