Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to make awk use bash instead of sh when running system commands using the system() call?

I want to use some bash-specific features such as [[ ]] and < > string comparison operators:

gawk 'BEGIN {system("if [[ \"porc\" == \"porc\" ]]; then echo yes; else echo no; fi")}'
sh: [[: not found
share|improve this question
Awk is quite a powerful utility. There is nothing so special about the features you mention that awk cannot do... eg. here is a simpler way to compare strings without the need for an unnecessary system call and the nuisance quoting. awk 'BEGIN{ if("abc" > "abcd") {print "yes"} else {print "no"} } ..(+1 for the question, because is it good to know how to do it, and maybe why not to do it :) – Peter.O Jun 16 '12 at 21:19
up vote 4 down vote accepted

If you want bash, you'll either have to patch gawk or call bash directly (the quoting gets a bit hairy):

gawk 'BEGIN {
    script="if [[ \"porc\" == \"porc\" ]]; then echo yes; else echo no; fi"
    system("bash -c '\''" script "'\''")
share|improve this answer
if those are the only options... – haelix Jun 16 '12 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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