Skip to main content
The 2024 Developer Survey results are live! See the results
edited tags; edited tags
Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992
Source Link
TimLer
  • 101
  • 2

How to use a variable in a command inside of a bash file

I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want:

grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }'

I need to automotize this procedure with a bash file and it looks like that it doesn't get the value of current_date variable:

#!/bin/bash
current_date=$(date "+%d-%b-%Y")
grep '$current_date' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out
grep "$current_date" /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out
grep $current_date /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ( $NF != 0 ) print $0 }' >> y.out

In all of these cases it return an empty value. Thank you in advance.