I am trying to create a bash script to check and generate report on CIS Benchmark for RHEL7 v2.1.0. I am getting some issue while handling variable in 'if' condition. Here is my script:-

[root@test ~]# cat test.sh
echo $(date) > ./report
echo $(date) > ./passed
echo $(date) > ./failed

echo -e "\n1.1.1.1\t Ensure mounting of cramfs filesystems is disabled" >> ./report
CMD='modprobe -n -v cramfs'
OPUT="install /bin/true"
if [ "$RPUT" == "$OPUT" ]
        echo -e "\nPASSED" >> ./report
        echo -e "$PROB" >> ./passed
        echo -e "\nFAILED" >> ./report
        echo -e "$PROB" >> ./failed
echo -e "Your Output:\n $RPUT \nRequired Output:\n $OPUT " >> ./report
[root@test ~]#
[root@test ~]# ./test.sh
[root@test ~]#
[root@test ~]# cat report
Mon Aug 12 11:56:19 IST 2019  Ensure mounting of cramfs filesystems is disabled

Your Output:
 install /bin/true
Required Output:
 install /bin/true
[root@test ~]#

Both the output are same but still the check is failing.


I put declare -p RPUT OPUT before the if statement which printed out put:

declare -- RPUT="install /bin/true "
declare -- OPUT="install /bin/true"

Now that extra space was creating problem so I added a space in OPUT variable. It resolved the problem.

| improve this answer | |
  • Asking follow-up questions/requests in answers is not the right thing to do. Posting a new question is, but note that asking for software recommendations is off-topic here on Super User. I edited your answer. – Kamil Maciorowski Aug 12 '19 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.