Setting a variable in a single line Bash script

Looking for a way to set a variable in bash single-line, i.e. a script, for example:

export class={read -p "What Is Your Profession?" a; case $a in "Theif") echo "Stealth" ; in "Cleric") echo "Heals?" ; "Monk") echo "Focus?" ; *) echo "invalid choice" a; esac}

Despite the fact that I am having problems with this command, without setting it to single-line, I tried it in different ways, and I did not get any results. The foregoing was most explicitly stated in my eyes. I also triedVAR= ,

The case itself gives me

-jailshell: syntax error near unexpected token `('

whenever I run it with a few cases. I know that this is probably all messed up.

+3
source share
2 answers

;;, case, . { … }, -. , {, } ; { ( ) ( ) }. . :

export class=$(read -p "What Is Your Profession?" a; case $a in "Theif") echo "Stealth" ;; "Cleric") echo "Heals?" ;; "Monk") echo "Focus?" ;; *) echo "invalid choice $a";; esac)

, "".

+5

-, :

export class=`{ read -p "What Is Your Profession? " a; case $a in "Theif") echo "Stealth";; "Cleric") echo "Heals?";; "Monk") echo "Focus?";; *) echo "invalid choice" a;; esac; }`

:

function readclass() { read -p "What Is Your Profession? " a; case $a in "Theif") echo "Stealth";; "Cleric") echo "Heals?";; "Monk") echo "Focus?";; *) echo "invalid choice" a;; esac; }

:

export class=$(readclass)
+2
source

All Articles