Skip to main content
1 of 2
Doron Behar
  • 783
  • 8
  • 27

Escaping gawk variables for shell commands

I'm trying to run a small gawk script which will run certain shell commands using system() on certain I want to get the file list with find and run the script like that:

find <arguments> -printf "%f\n" | script.awk

The problem is that these files have special characters such as spaces, quotes and parentheses in them. For example:

$ ls
'Aujourd'\''hui C'\''est Toi (Orchestral).flac'

I tried all sorts of quotes like the following:

system("<command> \""$0"\"")

And also this:

system("<command> \'"$0"\'")

And I get all sorts of errors, some of these errors are from the sh -c and some are from gawk...

Is there a way to pass the record $0 or other variables from the gawk script to a shell command with out encountering all of theses problems?

Note: I know it could have been easier to just rename the files temporarily but I find it more challenging to avoid it.

Doron Behar
  • 783
  • 8
  • 27