I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause.
testno=1;
date=20171128;
DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"'
I think that the problem you have is that you have single quoted the whole process. This will prevent the shell from interpolating your variables to build the command it executes. It will literally run what is shown.
Try the following very similar variation:-
DIR=/root/ sh -c "cd $DIR; tar cvf AWS.${testno.${date}.tar ./AWS
You could also try:-
DIR=/root
cd $DIR
tar cvf AWS.${testno.${date}.tar ./AWS
....or if you need to get back to where you started (and that could be anywhere)
DIR=/root
pushd $DIR
tar cvf AWS.${testno.${date}.tar ./AWS
popd