6

I want to use command line argument and use this value to replace in url in yarn script. My script looks like this -

"demo:req": "curl -s -D - -o /dev/null https://test.com/demo?request=true&type=${0} | grep -i '^location: ' | awk '{print $2}' | sed 's/https/http/' | sed 's/test.com/localhost:3012/'",

So when I run

yarn demo:req type1

it should replace the ${0} with type1 before triggering the curl command. But this is not working.

I tried to use ${TYPE} in url and run the command as

yarn demo:req TYPE=type1

but still no luck.

Any help would be really appreciated

RobC
  • 22,977
  • 20
  • 73
  • 80
Neha Gupta
  • 141
  • 2
  • 3
  • 1
    See here: https://stackoverflow.com/questions/11580961/sending-command-line-arguments-to-npm-script . You may be able to do something like `TYPE=type1 yarn demo:req` to run the command, and then the parameter $TYPE in your script definition in package.json. This should work in *nix environments, but it may not work in Command Prompt on Windows. – antun Jul 01 '21 at 21:13

0 Answers0