Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash-复合if语句_Bash - Fatal编程技术网

Bash-复合if语句

Bash-复合if语句,bash,Bash,如果目录不存在,我正在尝试安装NPM依赖项,但是这个速记不能正常工作 cd $(dirname "$0") if [[ ! -d "node_modules/babel-plugin-transform-runtime" ]] && npm install babel-plugin-transform-runtime if [[ ! -d "node_modules/babel-preset-es2015" ]] && npm instal

如果目录不存在,我正在尝试安装NPM依赖项,但是这个速记不能正常工作

    cd $(dirname "$0")
    if [[ ! -d "node_modules/babel-plugin-transform-runtime" ]] && npm install babel-plugin-transform-runtime
    if [[ ! -d "node_modules/babel-preset-es2015" ]] && npm install babel-preset-es2015
    if [[ ! -d "node_modules/babel-preset-es2016" ]] && npm install babel-preset-es2016
    if [[ ! -d "node_modules/babel-polyfill" ]] && npm install babel-polyfill
    if [[ ! -d "node_modules/babel-preset-stage-0" ]] && npm install babel-preset-stage-0
    if [[ ! -d "node_modules/babel-preset-stage-1" ]] && npm install babel-preset-stage-1
    if [[ ! -d "node_modules/babel-preset-stage-2" ]] && npm install babel-preset-stage-2
    if [[ ! -d "node_modules/babel-preset-stage-3" ]] && npm install babel-preset-stage-3
有一个语法错误-Bash需要一个“then”-我如何做我想做的事情?

在这些行中不需要if构造

[[ ! -d "node_modules/babel-plugin-transform-runtime" ]] && npm install babel-plugin-transform-runtime
很好。由于您是基于
test
运算符的返回码和
&
进行操作的,因此此处不需要
if..then
子句。如果您仍然对使用
If
子句感兴趣,可以使用以下经典方法:

if [[ ! -d "node_modules/babel-plugin-transform-runtime" ]]; then
    npm install babel-plugin-transform-runtime
fi

而且经常会立刻发现你的问题

这些行中的任何一行都不需要if构造

[[ ! -d "node_modules/babel-plugin-transform-runtime" ]] && npm install babel-plugin-transform-runtime
很好。由于您是基于
test
运算符的返回码和
&
进行操作的,因此此处不需要
if..then
子句。如果您仍然对使用
If
子句感兴趣,可以使用以下经典方法:

if [[ ! -d "node_modules/babel-plugin-transform-runtime" ]]; then
    npm install babel-plugin-transform-runtime
fi

而且经常会立刻发现你的问题