0

I have a function defined as follows in my zshrc

function k8sapi() {
    PREFIX='https://STABLE_URL'
    if [ "$1" == "prod" ];
    then
        PREFIX='https://PROD_URL'
    fi
echo "1 --> $1"
echo "2 --> $2"
curl -s "${PREFIX}/${2}"

}

When I run this:

$ k8sapi stable foo
k8sapi:2: = not found

What am I doing wrong? How do I look at arguments to a function in zsh?

These functions were copied over from my old laptop using bash shell, so I am trying to migrate them to zsh.

feroze
  • 103

1 Answers1

2

The problem is with your if condition. You should use just one = or you can also use [[ condition ]].

 if [[ $1 == "prod" ]];
 then
    PREFIX='https://PROD_URL'
 fi

Or:

 if [ "$1" = "prod" ];
 then
    PREFIX='https://PROD_URL'
 fi