0

I am facing problem while executing a find command from within a shell script. Am I doing something wrong here and is there a better way to implement it?

**test.sh**

cmd="find /etc/nginx -user root ! -perm -u+r+w -printf \"%u %g %p\""
rowN=$($cmd)
echo $rowN

sh test.sh
find: paths must precede expression: %g
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Konoha
  • 337
  • 1
  • 4
  • 13
  • 2
    I gave a answer, but capturing the output of find (and ls) like this is _usually_ an antipattern. Consider posting on codereview.stackexchange.com if you want more feedback. – kojiro Jan 27 '16 at 16:29
  • 2
    See [BashFAQ #50: I'm trying to put a command in a variable, but the complex cases always fail!](http://mywiki.wooledge.org/BashFAQ/050) and [this previous question](http://superuser.com/questions/280877/finding-files-in-linux-based-on-regex-with-multiple-alternatives). – Gordon Davisson Jan 27 '16 at 16:30
  • To second Gordon -- this is **absolutely** a BashFAQ #50 problem. – Charles Duffy Jan 27 '16 at 16:48

0 Answers0