We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chmod +x test.sh ./test.sh
#!/usr/bin/env sh
sed -i '' ’s/[regex]/[target]/g’ xx.txt
sed -i ‘xx/bb/g’ xx.txt 报错: extra characters at the end of x command
sed -i '' 's/xx/bb/g' xx.txt
xx.txt文件里的 xx改成了bb
set -e echo "Enter release beta version: " read VERSION
read -p "Releasing $VERSION - are you sure? (y/n)" -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then
test.sh: echo "Shell 传递参数实例!"; echo "执行的文件名:$0"; echo "第一个参数为:$1"; echo "第二个参数为:$2"; echo "第三个参数为:$3";
./test.sh 1 2 3
每当执行npm run,就会自动新建一个 Shell,在这个 Shell 里面执行指定的脚本命令。因此,只要是 Shell(一般是 Bash)可以运行的命令,就可以写在 npm 脚本里面。
比较特别的是,npm run新建的这个 Shell,会将当前目录的node_modules/.bin子目录加入PATH变量,执行结束后,再将PATH变量恢复原样。
这意味着,当前目录的node_modules/.bin子目录里面的所有脚本,都可以直接用脚本名调用,而不必加上路径。比如,当前项目的依赖里面有 Mocha,只要直接写mocha test就可以了。
"test": "mocha test"
而不用写成下面这样。
"test": "./node_modules/.bin/mocha test"
The text was updated successfully, but these errors were encountered:
No branches or pull requests
hello world
chmod +x test.sh
./test.sh
#!/usr/bin/env sh
直接修改文件内容sed
sed -i '' ’s/[regex]/[target]/g’ xx.txt
sed -i ‘xx/bb/g’ xx.txt
报错:
extra characters at the end of x command
sed -i '' 's/xx/bb/g' xx.txt
xx.txt文件里的 xx改成了bb
读写
set -e
echo "Enter release beta version: "
read VERSION
read -p "Releasing $VERSION - are you sure? (y/n)" -n 1 -r$REPLY =~ ^[Yy]$ ]]
echo # (optional) move to a new line
if [[
then
传参
test.sh:
echo "Shell 传递参数实例!";
echo "执行的文件名:$0";
echo "第一个参数为:$1";
echo "第二个参数为:$2";
echo "第三个参数为:$3";
./test.sh 1 2 3
与npm scripts的关系
每当执行npm run,就会自动新建一个 Shell,在这个 Shell 里面执行指定的脚本命令。因此,只要是 Shell(一般是 Bash)可以运行的命令,就可以写在 npm 脚本里面。
比较特别的是,npm run新建的这个 Shell,会将当前目录的node_modules/.bin子目录加入PATH变量,执行结束后,再将PATH变量恢复原样。
这意味着,当前目录的node_modules/.bin子目录里面的所有脚本,都可以直接用脚本名调用,而不必加上路径。比如,当前项目的依赖里面有 Mocha,只要直接写mocha test就可以了。
而不用写成下面这样。
参考文档
The text was updated successfully, but these errors were encountered: