Jorge Vega Sánchez
Jorge Vega Sánchez

Reputation: 7590

Variable assignment in KornShell

I've an weird error when trying to assign the value to a variable into another. The initial variable value contains ' signs at the beginning and at the end.

Here is the code :

server = $(uname -n)
passpre = "'HPre2053#'"
passmon = "'MonH2053#'"
mdp=""

echo ${server}

if [[ "$server" = "cly1024" ]]; 
then
    echo "Dentro Pre"
    mdp = $(passpre)
    echo $mdp
    logit "Exécution du script sur Pre. Mot de passe choisi."
elif [[ "$server" = "pcy4086" ]]; 
then
    echo "Dentro MON"
    mdp = ${passmon}
    logit "Exécution du script sur MON. Mot de passe choisi."
fi

Code error :

cly1024
Dentro Pre
modMDPconfig.ksh[51]: passpre:  not found
modMDPconfig.ksh[51]: mdp:  not found

Line 51 is where i do the variable assignation mdp = $(passpre)

Upvotes: 3

Views: 9739

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295353

This is wrong:

var = value

This is right:

var=value

Do not put spaces around the = operator in assignments.


A corrected form of this script follows:

server=$(uname -n)
passpre="'HPre2053#'"
passmon="'MonH2053#'"
mdp=""

echo "$server"

if [[ "$server" = "cly1024" ]]; then
    echo "Dentro Pre"
    mdp=$passpre
    echo "$mdp"
    logit "Exécution du script sur Pre. Mot de passe choisi."
elif [[ "$server" = "pcy4086" ]]; then
    echo "Dentro MON"
    mdp=$passmon
    logit "Exécution du script sur MON. Mot de passe choisi."
fi

Upvotes: 4

Related Questions