Search

Launch a terminal with random text color every time

We can set the color of the prompt using the print statement as given in the following link.

Using this info, we can create a script that will set the prompt to a random color every time we open or launch the console or terminal.



The variable $RANDOM will generate random numbers and "%" will ensure that the number will remain below 7, ensuring that the variable color will have only numbers between 30 and 37, which are the numbers of the console colors.

To make this piece of code run every time we open the terminal or console, we can add it to the file .bashrc of the user. So open the .bashrc and enter these two lines at the last and save it.

Remember, do not edit any thing in .bashrc unless you are not sure of what you are doing as it might make launching console difficult if you do wrong changes.


No comments:

Post a Comment