This question already has an answer here:

I can run this from the command line and it works: find /var/www/vhosts/foo/httpdocs/content/templates/ -name '*.plg' -print | xargs sed -i 's|mysql_|mysqli_|g'

So I wrote the following sed.sh file and call it like this: sed.sh foo


THESTART="find /var/www/vhosts/"
THEEND="/httpdocs/content/templates/ -name '*.plg' -print | xargs sed -i 's|mysql_|mysqli_|g'"

if [ -z "$THEPATH" ]; then
    echo "You must supply a path."
        exit 1




and i get the error: find: paths must precede expression: |

Why does it behave differently when run from a shell script?

marked as duplicate by Kusalananda bash Feb 15 at 7:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    As the error says you have to call it with a path. Does directory foo exists as a subdirectory – Rui F Ribeiro Feb 15 at 7:21
  • 1
    Your script puts a complex command in a variable. Never do that. Here's why: "I'm trying to put a command in a variable, but the complex cases always fail!" – John1024 Feb 15 at 7:40
  • Why the capital letters in the variable names? It is tradition that shell variables to be lower-case, and environment variables be upper-case. Breaking this tradition is bad luck (it can lead to name collisions, and buggy scripts). – ctrl-alt-delor Feb 15 at 8:56
  • Be glad this did not work, it would be vulnerable to code injection attack. – ctrl-alt-delor Feb 15 at 9:05

Browse other questions tagged or ask your own question.