Not sure why this is producing error. This is a test code emulating my real code. I want to write a wrapper for find
and want to allow for any argument, so I'm wrapping each arg in single quotes.
#!/bin/bash
function find2 {
ARGS="/usr/bin/find"
while [[ $# -gt 0 ]]; do
ARGS="$ARGS '$1'"
shift
done
echo CALLING: $ARGS
$ARGS
}
find2 /tmp/test -name "hello.c" # THIS IS THE DESIRED IMPLEMENTATION (doesn't work)
find '/tmp/test' '-name' 'hello.c' # THIS IS FOR DEBUGGING (works)
I want to "find2" work, but it doesn't work. I get the following output:
CALLING: /usr/bin/find '/tmp/test' '-name' 'hello.c'
/usr/bin/find: `\'/tmp/test\'': No such file or directory
/usr/bin/find: `\'-name\'': No such file or directory
/usr/bin/find: `\'hello.c\'': No such file or directory
however, if I use the exact same command (produced by find2) directly, it works fine:
/tmp/test/hello.c
Not sure what is going on.