Recently made the switch to Linux/command line, and I'm having trouble creating a dynamic greeting for terminal out of a list of predetermined possibilities.I tried the following, but it appears as if I can't figure out the correct syntax for the random.choice function I've been using.a=Affirmative, Dave. I read you.b=Good afternoon, Mr. Avers. Everything is going extremely well.c=My instructor was Mr. Langley, and he taught me to sing a song. If you'd like to hear it, I can sing it for you.random.choice(('a', 'b', 'c')) | echoAny script or creating-questions advice is welcome.Edit: I added these lines to ~/.bash_aliases, not ~/.bashrc as I don't want to mess with that file just yet.I was looking to get one of these greetings when opening terminal, and indeed, I didn't realize that random.choice was a python function.Using @MelBurslan 's code worked perfectly, but thank you to everyone who commented.
How to create a dynamic greeting?
command line;bashrc;random
You are confusing bash with python. random.choice is a python function. A similar effect can be attained using bash like this:greeting=(Affirmative, Dave. I read you. Good afternoon, Mr. Avers. Everything is going extremely well. Do you want me to sing a song for you ?)index=$(( RANDOM % ${#greeting[@]} ))echo ${greeting[${index}]}