0

I am developing a script in bash. This script receives a parameter by pipe and passes it to the script.

The problem is that the script is receiving null values.

# curl -s -d 'PATH_ROOT="/opt"' http://dominio.com/setup_cmi/install_cmi.sh |bash $PATH_ROOT esta vacia, debe indicar el directorio raiz

#!/bin/bash
#Dependencias
declare -a dependencias=( "unzip" "wget" "curl" "mkdir" "tree" )
#command -V unzip
echo "Content-Type: text/plain"
echo
PATH_ROOT=$1

if [ -z "$PATH_ROOT" ]; then
      echo "\$PATH_ROOT esta vacia, debe indicar el directorio raiz"
      exit;
else

       for i in "${dependencias[@]}"; do
              command -V $i
              if [ $? = 1 ]; then
                  exit;
              fi
        done

fi

Also try making the call in this way, with the same result:

curl -s http://dominio.com/setup_cmi/install_cmi.sh | bash -s -- /opt
Félix
  • 13
  • 4
  • Your second syntax is much closer to correct. `curl -d` is giving the data to the web server, not to the script, so it can't be expected to work. – Charles Duffy Mar 27 '20 at 21:59
  • ...did I say "much closer to correct"? It's not just closer, it's *actually correct*. You can test this yourself: `bash -s -- /opt <<<'echo "first argument is $1"'` passes `/opt` in the `$1` position. – Charles Duffy Mar 27 '20 at 22:01
  • BTW, `command -V $i; if [ $? = 1 ]; then exit; fi` would be much better written as `command -v "$i" || exit`. See https://stackoverflow.com/questions/36313216/why-is-testing-to-see-if-a-command-succeeded-or-not-an-anti-pattern – Charles Duffy Mar 27 '20 at 22:01
  • (As another aside, from a security perspective, running code you receive over plain HTTP without any kind of signature check is a Bad Idea; anyone running a man-in-the-middle can replace the script with anything else they want). – Charles Duffy Mar 27 '20 at 22:04
  • See the code running correctly at https://ideone.com/DOaD6F, *not* giving the stated error. – Charles Duffy Mar 27 '20 at 22:09
  • the problem is not the script, my problem is when I try to pass arguments to the script via pipe, output is null. Do you know how to do that? Thanks for your help. – Félix Mar 30 '20 at 14:30
  • Pass *arguments* via pipe? You can pass code via pipe, *or* arguments via pipe. You can't do both. As the link I gave showed, passing code via pipe and arguments on the command line works fine (see how the code is entered in the "stdin" field on ideone.com, so it's piped into the shell). That's what your `curl -s http://dominio.com/setup_cmi/install_cmi.sh | bash -s -- /opt` code does too. – Charles Duffy Mar 30 '20 at 15:14
  • Might I suggest something? Make it `curl -s http://dominio.com/setup_cmi/install_cmi.sh | tee install_cmi_localcopy.sh | bash -xs -- /opt`. Then compare `install_cmi_localcopy.sh` to your original script and make sure they're byte-for-byte identical, and give the xtrace log written to stderr a careful readthrough (or edit it into the question). – Charles Duffy Mar 30 '20 at 15:16
  • Or at least adjust your `dominio.com` site so people other than you can reach the script to be able to do sandboxed testing / reproduce the problem themselves. Right now, reading that URL from here I get a generic error about not being a member of that hosting service. – Charles Duffy Mar 30 '20 at 15:20

0 Answers0