Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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和bang(!)之间有什么区别_Bash_Google Cloud Platform_Gcloud_Shebang - Fatal编程技术网

(%%)bash和bang(!)之间有什么区别

(%%)bash和bang(!)之间有什么区别,bash,google-cloud-platform,gcloud,shebang,Bash,Google Cloud Platform,Gcloud,Shebang,在jupyter笔记本中,以下gcloud命令与bang一起工作!但不是用%%bash import os PROJECT = 'mle-1234' REGION = 'us-central1' BUCKET = 'mle-1234' File "<ipython-input-16-f93912dbcc34>", line 3 gcloud config set project $[PROJECT] ^ SyntaxError: i

在jupyter笔记本中,以下gcloud命令与bang一起工作!但不是用%%bash

import os

PROJECT = 'mle-1234' 
REGION = 'us-central1' 
BUCKET = 'mle-1234'
  File "<ipython-input-16-f93912dbcc34>", line 3
    gcloud config set project $[PROJECT]
                ^
SyntaxError: invalid syntax
当我使用%%bash执行上面的最后一个代码段时,收到此错误消息

import os

PROJECT = 'mle-1234' 
REGION = 'us-central1' 
BUCKET = 'mle-1234'
  File "<ipython-input-16-f93912dbcc34>", line 3
    gcloud config set project $[PROJECT]
                ^
SyntaxError: invalid syntax
结果与使用

Updated property [core/project].
Updated property [compute/region].

[compute]
region = us-central1
zone = us-central1-a
[core]
account = my-service-account@mle-1234.iam.gserviceaccount.com
disable_usage_reporting = False
project = mle-1234

What could be the reason for this behavior?
%%猛击 %%bash被认为是应用程序的一部分。在子流程中使用bash运行单元格。这是%%script bash的快捷方式。您可以将多个内核中的代码组合到一个笔记本中。例如:

实施:

%%bash

factorial()
{
    if [ "$1" -gt "1" ]
    then
        i=`expr $1 - 1`
        j=`factorial $i`
        k=`expr $1 \* $j`
        echo $k
    else
        echo 1
    fi
}

input=5
val=$(factorial $input)
echo "Factorial of $input is : "$val
! 命令 使用bang字符启动代码单元格,例如!,指示jupyter将该行上的代码视为

输出:

答:由于您使用的是gcloud命令,Jupyter会将这些命令解释为OS shell命令;因此,使用!glcoud会起作用的

%%猛击 %%bash被认为是应用程序的一部分。在子流程中使用bash运行单元格。这是%%script bash的快捷方式。您可以将多个内核代码组合到一个笔记本中。例如:

实施:

%%bash

factorial()
{
    if [ "$1" -gt "1" ]
    then
        i=`expr $1 - 1`
        j=`factorial $i`
        k=`expr $1 \* $j`
        echo $k
    else
        echo 1
    fi
}

input=5
val=$(factorial $input)
echo "Factorial of $input is : "$val
! 命令 使用bang字符启动代码单元格,例如!,指示jupyter将该行上的代码视为

输出:

答:由于您使用的是gcloud命令,Jupyter会将这些命令解释为OS shell命令;因此,使用!glcoud会起作用的


这似乎根本没有回答这个问题。使用%%bash应该会导致后续行被传递给bash进行解释,如果发生这种情况,它应该可以工作。。。但很明显,它们并没有被传递给bash,因为SyntaxError:invalid syntax不是bash错误。使用%%bash应该会导致后续行被传递给bash进行解释,如果发生这种情况,它应该可以工作。。。但很明显,它们并没有传递给bash,因为SyntaxError:invalid syntax不是bash错误。随机猜测:%%bash需要放置在第一行的神奇位置,类似于shebang!必须位于脚本的第一行。如果删除上面的注释并将%%bash放在第一行,会发生什么情况?有什么变化吗?随机猜测:%%bash需要放置在第一行的一个神奇位置,类似于shebang!必须位于脚本的第一行。如果删除上面的注释并将%%bash放在第一行,会发生什么情况?有变化吗?
%%bash

factorial()
{
    if [ "$1" -gt "1" ]
    then
        i=`expr $1 - 1`
        j=`factorial $i`
        k=`expr $1 \* $j`
        echo $k
    else
        echo 1
    fi
}

input=5
val=$(factorial $input)
echo "Factorial of $input is : "$val
!cat /etc/os-release | grep VERSION
VERSION="16.04 LTS (Xenial Xerus)"
VERSION_ID="16.04"