1

I have a shell script to configure container images for Kubernetes cluster, How can I run shell script from windows 10 PowerShell?

I have a shell script to configure container images for Kubernetes cluster, How can I run shell script from windows 10 PowerShell? I have Docker, and Google CloudSDK already install on my windows.

TAG=2.2

export IMAGE_PROMETHEUS="marketplace.gcr.io/google/prometheus:${TAG}"
export IMAGE_ALERTMANAGER="marketplace.gcr.io/google/prometheus/alertmanager:${TAG}"
export IMAGE_KUBE_STATE_METRICS="marketplace.gcr.io/google/prometheus/kubestatemetrics:${TAG}"
export IMAGE_NODE_EXPORTER="marketplace.gcr.io/google/prometheus/nodeexporter:${TAG}"
export IMAGE_GRAFANA="marketplace.gcr.io/google/prometheus/grafana:${TAG}"
export IMAGE_PROMETHEUS_INIT="marketplace.gcr.io/google/prometheus/debian9:${TAG}"

    for a in "IMAGE_PROMETHEUS" \
             "IMAGE_ALERTMANAGER" \
             "IMAGE_KUBE_STATE_METRICS" \
             "IMAGE_NODE_EXPORTER" \
             "IMAGE_GRAFANA" \
             "IMAGE_PROMETHEUS_INIT"; do
      repo=$(echo ${!i} | cut -d: -f1);
      digest=$(docker pull ${!i} | sed -n -e 's/Digest: //p');
      export $i="$repo@$digest";
      env | grep $i;
    done
1

1 Answer 1

1

Please note the tags windows and shell (POSIX shell) are mutually exclusive. What you have posted above is neither windows or POSIX shell, but rather bash (or another advanced shell supporting variable indirection (e.g. ${!i}).

You cannot run the script from PowerShell. (it has no clue how to interpret the syntax). The only way you can run it is in bash for windows (or more generally using WSL).

Why? Every 'script' language needs and interpreter. What is written in your question looks to be written for bash where the utilities sed and grep can be called, as well as docker pull. Check to see whether you have either bash for windows or a Linux distribution installed using WSL.

There is no way that cmd.exe or PowerShell can interpret the script without additional software providing a bash interpreter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.