Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] escaping variables in bash


awk '/regex/ {awk code}'

Here's a shell script that I put together call whatrpm.sh as in "whatrpm put that file on my 'puter". It shows a string being passed to awk and used as a search pattern. I append a "$" to the string that the user passes on the command line so that it only matches where the filename appears at the end of a line. (it won't work for partial file names and will trip up if the string matches the info data, but you get the idea).

P.

--

case $# in
1)
  search=`echo $1\$`
 ;;
*)
  printf "Usage: $0 <filename>\n" 1>&2
  exit
 ;;
esac


rpm -q -a -i -l | awk  --assign search=$search '
/Name        :/ { PRODUCT=$3}
$0 ~ search { printf("Rpm:%s, File:%s\n",PRODUCT,$0) }'