0

I'm working on a bash script to store the difference of packages from day to day in a debian based system.

I am toying around with the code below to get the functionality down before I fine tune it and running into difficulty with the line

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

It seems to be an issue with the variables as it works when I hardcode the file names and pkg.log contains the difference between the two. The variables work as expected when using the diff command so I'm not sure what the exact cause is.

#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

If anyone can help I would be very grateful.

  • 1
    If "works fine when I hardcode the names", then just print "$DIR//$TODAY" "$DIR//$PREV" out to see what happened. BTW, why double slash //? – PasteBT Dec 04 '13 at 00:44
  • I printed them both already and they work with the diff command below so I know the output is correct. As for the double slashes I started it a long time ago and just came back to this so I'm not sure what I was thinking with that. I have replace them with a single slashes. – Not_A_Dolphin Dec 05 '13 at 16:15

0 Answers0