0

私は、debian ベースのシステムで日々のパッケージの違いを保存するための bash スクリプトに取り組んでいます。

以下のコードをいじって、機能をダウンさせてから、微調整してラインで問題が発生するようにしています。

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

ファイル名をハードコーディングし、 pkg.log に2つの違いが含まれている場合に機能するため、変数に問題があるようです。変数は 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