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)
mdp = $(passpre)is not doing an assignment at all. It runs a commandmdpwith the first argument=and the second command the output of runningpasspreas a command. Given this, the error message it gives you is entirely descriptive of the problem."'foo'", the'quotes are data, and the"quotes are syntax) are never able to substitute for syntactical quotes. When you do a parameter expansion, data always stays data -- it can't turn into syntax unless you're then explicitly running that data through an evaluation pass, and doing so is very bad form for security reasons.shfamily must consist of a single string containing an=sign. On the left side must be a valid variable name (alphanumeric + underscore), the right side can contain anything, but whitespace must be quoted. The normal difference for"..."and'...'quoting apply.