简体   繁体   English

az vim run-command使用参数调用shell脚本

[英]az vim run-command invoke shell script with parameters

I want to run a script using az cli invoke. 我想使用az cli调用运行脚本。

I_PASS_THIS_VAR=${1}
az vm run-command invoke     --command-id RunShellScript \
                                 --scripts '@foo.sh' \
                                 --parameters=${I_PASS_THIS_VAR} \
                                 -o tsv

where I pass $I_PASS_THIS_VAR and it is some string. 我传递$ I_PASS_THIS_VAR的地方,它是一些字符串。 Then the foo.sh is: 然后foo.sh是:

#!/bin/bash
PARAM=${1}
if [ ${PARAM} ]
then
    echo "export MY_PARAM=${PARAM}" >> "${HOME_DIR}/.bashrc"
fi

I does not work. 我不工作。 The MY_PARAM equals nothing. MY_PARAM等于零。 Why ? 为什么?

To run the shell script in a Linux VM, the command should like this: 要在Linux VM中运行shell脚本,命令应如下所示:

az vm run-command invoke -g group_name -n vm_name --command-id RunShellScript --scripts @run_command.sh --parameters param1

The shell script is in the place where you run the Azure CLI command. shell脚本位于运行Azure CLI命令的位置。 And the shell script for you will like this: 你的shell脚本会喜欢这个:

if [ $1 ]
then
        echo "export My_Param=$1" >> "/path/.bashrc"
fi

You can input the parameters in the Azure CLI command as the value of --parameter and quote them in the shell script like the above code. 您可以在Azure CLI命令中输入参数作为--parameter的值,并在shell脚本中引用它们,就像上面的代码一样。 One point you should take care of is that the path in the above code should be an absolute path. 你应该照顾的一点是,该path在上面的代码应该是绝对路径。 For example, /home/useraccount/.bashrc and the useraccount is the user you want to export the environment variable. 例如,/ /home/useraccount/.bashrc / useraccount /home/useraccount/.bashrcuseraccount是您要导出环境变量的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM