0

In c shell script, I'm trying to pass bbb to awk sub, but apparently it does not work.

#!/bin/csh
set aaa=a
set bbb=b

#And I'm using it in awk sub

set ccc=`echo $aaa | awk '{sub("a",$bbb); print $0}'`

echo $ccc

But echos empty and dunno why.

Note if I replace $bbb with "b" then it works well.

cdnszip
  • 253

1 Answers1

1

You have to pass the shell variable to awk. Either with

set ccc=`echo $aaa | awk -v bb=$bbb '{sub("a",bb); print $0}'`

either close and reopen the awk quoting when referring to the shell variable :

set ccc=`echo $aaa | awk '{sub("a",'$bbb'); print $0}'`
magor
  • 3,752
  • 2
  • 13
  • 28