1

So I have written a simple bash script to run a program called "cmatrix" everytime a new terminal window is opened.

I have changed the permissions on the file so it is r-x for everyone, and verified that it will run exactly how I want it to when called, but now I don't know where to put the script so that it runs on each new bash terminal launch. I know that if I want it to run on startup I would place it in usr/local/bin, but I only want it to run when I open a new terminal window.

Very very simple:

cmatrix -bs -C cyan

Any and all help is appreciated!

Thanks

asked Jan 23, 2019 at 9:01
1
  • What do you mean by "terminal window"? A window from a (specific?) terminal emulator? Any tty? Any interactive Bash session? Please edit the question and clarify. (Side note: I think /usr/local/bin has nothing to do with running anything on startup. Not really relevant to your question though, even if I'm right). Commented Jan 23, 2019 at 9:27

1 Answer 1

5

Assuming bash is your default shell, any bash command you put into your ~/.bashrc file will be executed when opening a new terminal window (interactive shell). For example, putting echo "Hello" at the end of your ~/.bashrc file will popup this message)

For your script to be executed on opening a new bash window, you can just:

  1. Move your script to /usr/local/bin/
  2. Call your script from your ~/.bashrc file

Notice:

  1. You don't absolutely need to move your script to /usr/local/bin/, but it's convenient as it doesn't require the extra step to modify your path, or to call your script with its absolute path.

  2. To actually call your script from your ~/.bashrc, just add your script name at the end of the file:

    my_cool_script.sh

  3. If your script is a single line long, you can actually put that line in your ~/.bashrc instead of your script name, in your case:

    cmatrix -bs -C cyan

answered Jan 23, 2019 at 9:32
1
  • @KamilMaciorowski Thanks for the polished details. Answer edited. Commented Jan 23, 2019 at 10:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.