Auto start script when I open Terminal

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
CallMeCupcake

Auto start script when I open Terminal

Post by CallMeCupcake »

Hello, I tried looking for this type of thing I want to do but the ones I find tend to be more for multiple scripts at one time. So what i want to do is run a script every time I open terminal. The script isn't anything special, its just a saying that I like to see when I open terminal. Just seeing if anyone can help me with this.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
FreedomTruth
Level 4
Level 4
Posts: 443
Joined: Fri Sep 23, 2016 10:19 am

Re: Auto start script when I open Terminal

Post by FreedomTruth »

I think what you want is something like .profile in your home directory -- it gets executed when you log in with the default shell, I believe. If you happened to change to csh, use .login instead. Just add the script(s) to be executed at the end of .profile
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Auto start script when I open Terminal

Post by all41 »

This varies according to your mint install.
Post back results of terminal inquiry:

Code: Select all

inxi -S
You can make a launcher to do this, or you can do this with a custom keyboard shortcut.
Explain more of what you wish to accomplish.
Everything in life was difficult before it became easy.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Auto start script when I open Terminal

Post by xenopeek »

Just put it in the file .bashrc in your home directory. Anything you put in there is run when you open a new shell session (what happens when you open a terminal).

For example this is the welcome message code that I have in my .bashrc file:

Code: Select all

echo -n "$(uname -sr | cut -d'-' -f1) $(uname -m)"
type -P systemctl >/dev/null && echo -n " / $(systemctl --version | head -n1)"
case "${XDG_CURRENT_DESKTOP}" in
GNOME)
	echo -n " / $(gnome-shell --version)" ;;
KDE)
	echo -n " / KDE Plasma $(plasmashell --version | cut -d' ' -f2)" ;;
XFCE)
	echo -n " / Xfce $(xfce4-session --version | head -n1 | cut -d' ' -f2)" ;;
X-Cinnamon)
	echo -n " / Cinnamon $(cinnamon-session --version | cut -d' ' -f2)" ;;
MATE)
	echo -n " / MATE $(mate-session --version | cut -d' ' -f2)" ;;
*)
	;;
esac
[[ -n ${XDG_SESSION_TYPE} ]] && echo -n " / ${XDG_SESSION_TYPE^}"
echo
On one line it displays your kernel version, systemd version (if using systemd), and what desktop session you are running and its version and if known the session type (X11 or Wayland). inxi can probably do something similar but I like my own output here and use it across most of my systems.
Image
Locked

Return to “Scripts & Bash”