Automatically end each command in terminal with a different message or sound

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
21
down vote

favorite
2












I installed SVOX pico2wave and created a script.
Now when I enter:



speech "Hello world"


The computer text-to-voice engine says out loud "Hello world". Furthermore, I use in .bashrc the variable PROMPT_COMMAND defined as:



PROMPT_COMMAND="speech 'Command executed.'"


So the nice text-to-voice engine announces me loud that the command is executed, before returning the prompt in the terminal.



However, this gets boring after a while and I thought it would be really cool to end each command in terminal with the computer speaking a different line of text (think of the autopilot of Starship Enterprise).



So I created in .bashrc an array variable, with different messages:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."


What I would like, is that each time I run a command in terminal, the variable PROMPT_COMMAND to be updated and read a different random line in the array.



I presume I need a loop, but I didn't know how to make it.



I would be most grateful for any help. Thank you.










share|improve this question























  • In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
    – Terrance
    Sep 10 at 14:07










  • Thanks, indeed. This needs to be taken care of, but I had done it.
    – RazTaz
    Sep 10 at 14:29










  • Yeah, that is just a comment in general. Pretty cool idea here! +1
    – Terrance
    Sep 10 at 14:30










  • Just curious - how can I install speech executable? Is it alias for espeak?
    – N0rbert
    Sep 10 at 14:44







  • 1




    "speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
    – RazTaz
    Sep 10 at 14:55















up vote
21
down vote

favorite
2












I installed SVOX pico2wave and created a script.
Now when I enter:



speech "Hello world"


The computer text-to-voice engine says out loud "Hello world". Furthermore, I use in .bashrc the variable PROMPT_COMMAND defined as:



PROMPT_COMMAND="speech 'Command executed.'"


So the nice text-to-voice engine announces me loud that the command is executed, before returning the prompt in the terminal.



However, this gets boring after a while and I thought it would be really cool to end each command in terminal with the computer speaking a different line of text (think of the autopilot of Starship Enterprise).



So I created in .bashrc an array variable, with different messages:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."


What I would like, is that each time I run a command in terminal, the variable PROMPT_COMMAND to be updated and read a different random line in the array.



I presume I need a loop, but I didn't know how to make it.



I would be most grateful for any help. Thank you.










share|improve this question























  • In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
    – Terrance
    Sep 10 at 14:07










  • Thanks, indeed. This needs to be taken care of, but I had done it.
    – RazTaz
    Sep 10 at 14:29










  • Yeah, that is just a comment in general. Pretty cool idea here! +1
    – Terrance
    Sep 10 at 14:30










  • Just curious - how can I install speech executable? Is it alias for espeak?
    – N0rbert
    Sep 10 at 14:44







  • 1




    "speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
    – RazTaz
    Sep 10 at 14:55













up vote
21
down vote

favorite
2









up vote
21
down vote

favorite
2






2





I installed SVOX pico2wave and created a script.
Now when I enter:



speech "Hello world"


The computer text-to-voice engine says out loud "Hello world". Furthermore, I use in .bashrc the variable PROMPT_COMMAND defined as:



PROMPT_COMMAND="speech 'Command executed.'"


So the nice text-to-voice engine announces me loud that the command is executed, before returning the prompt in the terminal.



However, this gets boring after a while and I thought it would be really cool to end each command in terminal with the computer speaking a different line of text (think of the autopilot of Starship Enterprise).



So I created in .bashrc an array variable, with different messages:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."


What I would like, is that each time I run a command in terminal, the variable PROMPT_COMMAND to be updated and read a different random line in the array.



I presume I need a loop, but I didn't know how to make it.



I would be most grateful for any help. Thank you.










share|improve this question















I installed SVOX pico2wave and created a script.
Now when I enter:



speech "Hello world"


The computer text-to-voice engine says out loud "Hello world". Furthermore, I use in .bashrc the variable PROMPT_COMMAND defined as:



PROMPT_COMMAND="speech 'Command executed.'"


So the nice text-to-voice engine announces me loud that the command is executed, before returning the prompt in the terminal.



However, this gets boring after a while and I thought it would be really cool to end each command in terminal with the computer speaking a different line of text (think of the autopilot of Starship Enterprise).



So I created in .bashrc an array variable, with different messages:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."


What I would like, is that each time I run a command in terminal, the variable PROMPT_COMMAND to be updated and read a different random line in the array.



I presume I need a loop, but I didn't know how to make it.



I would be most grateful for any help. Thank you.







command-line bash sound






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 22 at 10:05

























asked Sep 10 at 13:38









RazTaz

15611




15611











  • In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
    – Terrance
    Sep 10 at 14:07










  • Thanks, indeed. This needs to be taken care of, but I had done it.
    – RazTaz
    Sep 10 at 14:29










  • Yeah, that is just a comment in general. Pretty cool idea here! +1
    – Terrance
    Sep 10 at 14:30










  • Just curious - how can I install speech executable? Is it alias for espeak?
    – N0rbert
    Sep 10 at 14:44







  • 1




    "speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
    – RazTaz
    Sep 10 at 14:55

















  • In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
    – Terrance
    Sep 10 at 14:07










  • Thanks, indeed. This needs to be taken care of, but I had done it.
    – RazTaz
    Sep 10 at 14:29










  • Yeah, that is just a comment in general. Pretty cool idea here! +1
    – Terrance
    Sep 10 at 14:30










  • Just curious - how can I install speech executable? Is it alias for espeak?
    – N0rbert
    Sep 10 at 14:44







  • 1




    "speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
    – RazTaz
    Sep 10 at 14:55
















In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
– Terrance
Sep 10 at 14:07




In the script in the linked answer, make sure you change the -l=de-DE to your local language like -l=en-US.
– Terrance
Sep 10 at 14:07












Thanks, indeed. This needs to be taken care of, but I had done it.
– RazTaz
Sep 10 at 14:29




Thanks, indeed. This needs to be taken care of, but I had done it.
– RazTaz
Sep 10 at 14:29












Yeah, that is just a comment in general. Pretty cool idea here! +1
– Terrance
Sep 10 at 14:30




Yeah, that is just a comment in general. Pretty cool idea here! +1
– Terrance
Sep 10 at 14:30












Just curious - how can I install speech executable? Is it alias for espeak?
– N0rbert
Sep 10 at 14:44





Just curious - how can I install speech executable? Is it alias for espeak?
– N0rbert
Sep 10 at 14:44





1




1




"speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
– RazTaz
Sep 10 at 14:55





"speech" is a script. I followed the instructions in the link. I made a script called speech.sh, including the corrections indicated above by Terrance". I saved speech.sh in my ~/scripts folder. I changed file permissions to speech.sh to make it executable. I created a folder as follows: ~/scripts/bin and followed the instructions from here stackoverflow.com/a/20054809, in order to add it to the PATH, so the script can be recognized as executable, no matter where I am.
– RazTaz
Sep 10 at 14:55











2 Answers
2






active

oldest

votes

















up vote
22
down vote



accepted










Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


Then in your .bashrc or .profile set PROMPT_COMMAND:



PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"


Just replace the speech with echo to get a messge instead of the voice.






share|improve this answer






















  • Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
    – RazTaz
    Sep 10 at 14:15










  • It works!!! Thank you so much!!!!
    – RazTaz
    Sep 10 at 14:28










  • @RazTaz You're welcome ;)
    – Ravexina
    Sep 10 at 14:28










  • Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
    – Mad Physicist
    Sep 11 at 14:02










  • @MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
    – Ravexina
    Sep 11 at 14:14


















up vote
4
down vote













Later Edit Tutorial:



Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04



1. Install SVOX pico2wave package:



sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3


2. Create the speech script



cd ~/scripts
gedit speech


and put this content inside, inserting the correct user in the path:



#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav


save and exit.



3. Create the shell_speech.sh script as indicated by Ravexina above:



gedit shell_speech




array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


save and exit.



4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:



chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts


5. Modify .bashrc



gedit ~/.bashrc


add the following line:



PROMPT_COMMAND="bash shell_speech"


save and close



Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech






share|improve this answer






















  • Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
    – Dennis Williamson
    Sep 11 at 0:31







  • 1




    For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
    – Hastur
    Sep 11 at 8:55











  • @Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
    – RazTaz
    Sep 15 at 9:23










  • @RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
    – Hastur
    Sep 15 at 16:35











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1073976%2fautomatically-end-each-command-in-terminal-with-a-different-message-or-sound%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
22
down vote



accepted










Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


Then in your .bashrc or .profile set PROMPT_COMMAND:



PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"


Just replace the speech with echo to get a messge instead of the voice.






share|improve this answer






















  • Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
    – RazTaz
    Sep 10 at 14:15










  • It works!!! Thank you so much!!!!
    – RazTaz
    Sep 10 at 14:28










  • @RazTaz You're welcome ;)
    – Ravexina
    Sep 10 at 14:28










  • Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
    – Mad Physicist
    Sep 11 at 14:02










  • @MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
    – Ravexina
    Sep 11 at 14:14















up vote
22
down vote



accepted










Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


Then in your .bashrc or .profile set PROMPT_COMMAND:



PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"


Just replace the speech with echo to get a messge instead of the voice.






share|improve this answer






















  • Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
    – RazTaz
    Sep 10 at 14:15










  • It works!!! Thank you so much!!!!
    – RazTaz
    Sep 10 at 14:28










  • @RazTaz You're welcome ;)
    – Ravexina
    Sep 10 at 14:28










  • Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
    – Mad Physicist
    Sep 11 at 14:02










  • @MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
    – Ravexina
    Sep 11 at 14:14













up vote
22
down vote



accepted







up vote
22
down vote



accepted






Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


Then in your .bashrc or .profile set PROMPT_COMMAND:



PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"


Just replace the speech with echo to get a messge instead of the voice.






share|improve this answer














Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:



array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


Then in your .bashrc or .profile set PROMPT_COMMAND:



PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"


Just replace the speech with echo to get a messge instead of the voice.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 10 at 14:26

























answered Sep 10 at 13:53









Ravexina

28.7k146998




28.7k146998











  • Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
    – RazTaz
    Sep 10 at 14:15










  • It works!!! Thank you so much!!!!
    – RazTaz
    Sep 10 at 14:28










  • @RazTaz You're welcome ;)
    – Ravexina
    Sep 10 at 14:28










  • Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
    – Mad Physicist
    Sep 11 at 14:02










  • @MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
    – Ravexina
    Sep 11 at 14:14

















  • Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
    – RazTaz
    Sep 10 at 14:15










  • It works!!! Thank you so much!!!!
    – RazTaz
    Sep 10 at 14:28










  • @RazTaz You're welcome ;)
    – Ravexina
    Sep 10 at 14:28










  • Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
    – Mad Physicist
    Sep 11 at 14:02










  • @MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
    – Ravexina
    Sep 11 at 14:14
















Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
– RazTaz
Sep 10 at 14:15




Thanks for the above solution. It seems to work, except that it only renders the first word in the random line (eg. "Shields." or "Deploying..") not the entire line (eg. "Shields at 90%" or "Deploying repair droids on dek 17."
– RazTaz
Sep 10 at 14:15












It works!!! Thank you so much!!!!
– RazTaz
Sep 10 at 14:28




It works!!! Thank you so much!!!!
– RazTaz
Sep 10 at 14:28












@RazTaz You're welcome ;)
– Ravexina
Sep 10 at 14:28




@RazTaz You're welcome ;)
– Ravexina
Sep 10 at 14:28












Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
– Mad Physicist
Sep 11 at 14:02




Shouldn't $array[$RANDOM % $#array[@]] be in double quotes?
– Mad Physicist
Sep 11 at 14:02












@MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
– Ravexina
Sep 11 at 14:14





@MadPhysicist It's a good practice but not necessary here, run the script using set -x to see what I'm talking about :)
– Ravexina
Sep 11 at 14:14













up vote
4
down vote













Later Edit Tutorial:



Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04



1. Install SVOX pico2wave package:



sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3


2. Create the speech script



cd ~/scripts
gedit speech


and put this content inside, inserting the correct user in the path:



#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav


save and exit.



3. Create the shell_speech.sh script as indicated by Ravexina above:



gedit shell_speech




array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


save and exit.



4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:



chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts


5. Modify .bashrc



gedit ~/.bashrc


add the following line:



PROMPT_COMMAND="bash shell_speech"


save and close



Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech






share|improve this answer






















  • Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
    – Dennis Williamson
    Sep 11 at 0:31







  • 1




    For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
    – Hastur
    Sep 11 at 8:55











  • @Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
    – RazTaz
    Sep 15 at 9:23










  • @RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
    – Hastur
    Sep 15 at 16:35















up vote
4
down vote













Later Edit Tutorial:



Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04



1. Install SVOX pico2wave package:



sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3


2. Create the speech script



cd ~/scripts
gedit speech


and put this content inside, inserting the correct user in the path:



#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav


save and exit.



3. Create the shell_speech.sh script as indicated by Ravexina above:



gedit shell_speech




array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


save and exit.



4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:



chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts


5. Modify .bashrc



gedit ~/.bashrc


add the following line:



PROMPT_COMMAND="bash shell_speech"


save and close



Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech






share|improve this answer






















  • Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
    – Dennis Williamson
    Sep 11 at 0:31







  • 1




    For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
    – Hastur
    Sep 11 at 8:55











  • @Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
    – RazTaz
    Sep 15 at 9:23










  • @RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
    – Hastur
    Sep 15 at 16:35













up vote
4
down vote










up vote
4
down vote









Later Edit Tutorial:



Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04



1. Install SVOX pico2wave package:



sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3


2. Create the speech script



cd ~/scripts
gedit speech


and put this content inside, inserting the correct user in the path:



#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav


save and exit.



3. Create the shell_speech.sh script as indicated by Ravexina above:



gedit shell_speech




array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


save and exit.



4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:



chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts


5. Modify .bashrc



gedit ~/.bashrc


add the following line:



PROMPT_COMMAND="bash shell_speech"


save and close



Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech






share|improve this answer














Later Edit Tutorial:



Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04



1. Install SVOX pico2wave package:



sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3


2. Create the speech script



cd ~/scripts
gedit speech


and put this content inside, inserting the correct user in the path:



#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav


save and exit.



3. Create the shell_speech.sh script as indicated by Ravexina above:



gedit shell_speech




array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=$array[$RANDOM % $#array[@]]
speech "$line"


save and exit.



4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:



chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts


5. Modify .bashrc



gedit ~/.bashrc


add the following line:



PROMPT_COMMAND="bash shell_speech"


save and close



Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 10 at 20:20









Ravexina

28.7k146998




28.7k146998










answered Sep 10 at 19:07









RazTaz

15611




15611











  • Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
    – Dennis Williamson
    Sep 11 at 0:31







  • 1




    For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
    – Hastur
    Sep 11 at 8:55











  • @Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
    – RazTaz
    Sep 15 at 9:23










  • @RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
    – Hastur
    Sep 15 at 16:35

















  • Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
    – Dennis Williamson
    Sep 11 at 0:31







  • 1




    For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
    – Hastur
    Sep 11 at 8:55











  • @Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
    – RazTaz
    Sep 15 at 9:23










  • @RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
    – Hastur
    Sep 15 at 16:35
















Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
– Dennis Williamson
Sep 11 at 0:31





Since you've made the script executable and in the PATH, you don't need to include bash in your PROMPT_COMMAND and I would use single quotes in case you add other things later that will need to have deferred execution: PROMPT_COMMAND='shell_speech'
– Dennis Williamson
Sep 11 at 0:31





1




1




For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
– Hastur
Sep 11 at 8:55





For security reasons it is better to write /bin/bash instead of a simple bash... (good practice just in case someone put another bash in your path before /bin...). I should even suggest you a temp random file in the /tmp directory instead that test.wav in your home... ps> give it a look to fortune.
– Hastur
Sep 11 at 8:55













@Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
– RazTaz
Sep 15 at 9:23




@Hastur think for a minute under what circumstances your assumption can become true (i.e "someone put another bash in your path before /bin"). This is possible only if someone either has physical access to your computer and/or has already escalated privileges. Under both circumstances, your solution is not fixing the problem.
– RazTaz
Sep 15 at 9:23












@RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
– Hastur
Sep 15 at 16:35





@RazTaz World is full of colors, not just black and white! :-). Unfortunately there are a lot of ways to have partial privileges on a system, and to use only bash is a way to obtain more. Links, script, write permission on open directories, shared ones... Moreover -- you may miss it -- scripts can survive to their first aim or owner... and you (or someone else) can use them after enough time that you do not remember all the commands written inside (we do for that), under different conditions. To put binbash with the explicit path is a good practice. To avoid to do it... a risk.
– Hastur
Sep 15 at 16:35


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1073976%2fautomatically-end-each-command-in-terminal-with-a-different-message-or-sound%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)