0

I have this base command: SOME_VAR='blabhablhaba' bash -c "$(curl -L https://run_script.sh)"

How do I do this with the posix shell? This fails: SOME_VAR='blabhablhaba' sh -c "$(curl -L https://run_script.sh)"

sh: syntax error: unexpected "("
0

1 Answer 1

2

Either you're using the wrong sort of quotes, or the shell script you're downloading is a bash script rather than a POSIX sh script.

What you have at the moment is that the curl is executed with the current shell, and the result pasted into the sh -c "..." expression ready for execution by sh.

Try this, which defers the entire download and execution to sh,

SOME_VAR='blabhablhaba' sh -c '$(curl -L https://run_script.sh)'

(The URL you've included as your example is flawed, in that there's no remote hostname. I'm assuming that's because it's a placeholder example.)

In all cases you should be aware that you are implicitly trusting the remote system not to deliver you a malicious script. Do you also trust their security?

2
  • 1
    though note that sh -c '$(...)' is quite different from sh -c "$(...)", they'd do the same thing only if the command outputs a simple command with no redirections or such. The first one would need to have an eval there to get the same effect as the second. But yeah, I think the issue is that the downloaded script needs Bash and not sh.
    – ilkkachu
    Mar 1, 2022 at 23:45
  • Yes SOME_VAR='blabhablhaba' sh -c '$(curl -L https://run_script.sh)' where sh does a split+glob on the output of curl makes little sense. SOME_VAR='blabhablhaba' sh -c 'eval "$(curl -L https://run_script.sh)"' would make more sense but be little different from the OP's original. I think we all agree the problem is likely that curl outputs some code that is not in the sh language. I'd bet it uses ksh-style process substitution here like cmd <(...). Mar 2, 2022 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .