sh - Getting value from function, use that value to get colored output in shell -


(using zsh) trying random color output whenever open new tab in terminal. achieve wrote following shell script, not working expected:

#standard colors red='\033[0;31m' nc='\033[0m' # no color black='\033[0;30m' blue='\033[0;34m' green='\033[0;32m' cyan='\033[0;36m' purple='\033[0;35m' yellow='\033[1;33m' lgreen='\033[1;32m' lblue='\033[1;34m' lred='\033[1;31m' lcyan='\033[1;36m' #array color colr=(red blue green cyan purple yellow lgreen lblue lred lcyan)  #get random number colors randcolr() {   sz=${#colr[@]}   randval=$(( ( random % sz )  + 1 ))   echo "${colr[randval]}" }  echo -e "$(randcolr)testing" 

instead of getting colored output, wrote name of color , "testing" e.g. lgreentesting. help?(i using zsh)

the function randcolr gives same value inside terminal.

when define array, using strings instead of variables:

colr=(red blue green cyan purple yellow lgreen lblue lred lcyan) 

should be:

colr=($red $blue $green $cyan $purple $yellow $lgreen $lblue $lred $lcyan) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -