so i'm confused about the relationship between my custom npm scripts and the bash scripts they run. EDIT : i don't think this an isolated bash issue. i can produce the expected behavior described below by writing echo $2 $1
into an .sh file and running it directly from the terminal
for example
"scripts": {"report":"echo $2 $1"}
if i run it from the terminal: npm run report "first" "second"
because in my npm script, i call $2
BEFORE $1
, i expect it to output this: second first
, but for some reason it always prints $1
first: first second
(edited)
i tried a workaround by caching my arguments as variables and then print those:
"scripts": {"report": "(FIRST=$1 && SECOND=$2) && echo $SECOND $FIRST"}
but same output: npm run report "first" "second"
=> first second
what gives?
The following bash file works good for me:
echo $2 $1
Run with:
bash file.sh 1 2
Output:
2 1
EDIT*:
The problem is with the way you try to use node. It seems the $X variables are not populated by node. It just appends your arguments to the rest of your command.
EDIT*2:
workaround
{
"scripts": {"report":"a(){ echo $2 $1; };a"}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.