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
Noor Ameen
  • 101
  • 2
  • 6
  • Does this answer your question? [How to run .sh on Windows Command Prompt?](https://stackoverflow.com/questions/26522789/how-to-run-sh-on-windows-command-prompt) – Michael Freidgeim Mar 05 '21 at 05:56

1 Answers1

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.

David C. Rankin
  • 81,885
  • 6
  • 58
  • 85