I would like to execute a shell command within a Groovy script where part of the script is variable of a filename which may contain spaces.
According to groovy execute with parameters containing spaces I may use an array for this:
def filename = '/tmp/folder with spaces'
// does not work
'ls "' + filename + '"'.execute()
// works
['ls', filename].execute()
But I can't figure out how to reformat the following command using an array where "filename" is a groovy variable containing a filename with or without spaces:
mdfind "$(/usr/libexec/PlistBuddy -c 'Print RawQuery' filename)"
This does not work:
// not working
["mdfind", "\$(/usr/libexec/PlistBuddy -c 'Print RawQuery' " + filename + ")"].execute()
["mdfind", "\$(/usr/libexec/PlistBuddy -c 'Print RawQuery' ", filename, ")"].execute()