简体   繁体   English

source 命令没有使用 shell 脚本将变量导出到 zsh 环境

[英]source command didn't export variables to the zsh environment using shell script

I have a really simple shell script which work really well on bash and export the varialbes to the current bash enviornment but unfortunately it didn't export the variables to the zsh enviornment.我有一个非常简单的 shell 脚本,它在 bash 上运行得非常好,并将变量导出到当前的 bash 环境,但不幸的是它没有将变量导出到 zsh 环境。

#!/bin/bash
export AWS_ACCESS_KEY_ID=$(echo $RESULT | jq --raw-output .Credentials.AccessKeyId)
export AWS_SECRET_ACCESS_KEY=$(echo $RESULT | jq --raw-output .Credentials.SecretAccessKey)
export AWS_SECURITY_TOKEN=$(echo $RESULT | jq --raw-output .Credentials.SessionToken)

and I am running this script like this:我正在像这样运行这个脚本:

source myscript.sh

OR或者

. ./myscript.sh

Please advise, that how I can make it work on the zsh environment?请指教,我怎样才能让它在 zsh 环境中工作?

There is nothing wrong in the code you have posted.您发布的代码没有任何问题。

Are your variables simply not defined, or are they defined and not exported, in the sourcing script?在采购脚本中,您的变量是未定义,还是已定义但未导出?

I would turn on set -x before sourcing, and analyze the output.我会在采购之前打开set -x并分析输出。 Maybe you have some commands in your sourced script, where the behaviour differs between bash and zsh.也许您的源脚本中有一些命令,其中 bash 和 zsh 的行为不同。 From the three lines you have posted, I don't see any incompatibilities though.从您发布的三行中,我没有看到任何不兼容性。

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

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