0

How can I write a bash that will execute at login and starts a terminal with message.

pseado code: .bash_login

#!/bin/bash

gnome-terminal
echo "hello user $username";

Just trying to learn some bash skills. Can someone please point me to a good tutorial about this or show me how to do this.

1 Answer 1

0

The gnome-terminal manual shows an option to execute a command in the terminal it opens.

   -x, --execute
             Execute  the  remainder  of  the  command  line  inside   the
             terminal.

But the catch is that once the command finishes, the terminal will close. This thread has a solution for that:

gnome-terminal -x bash -c "echo 'hello world' ; bash"

This will open the terminal and run the bash shell, which then runs the echo and then bash. This is essentially the same thing as a script like:

#!/bin/bash

echo 'hello world'
bash

So gnome-terminal -x script.sh should run the echo and leave you with a bash shell. Once you exit that shell, the original (bash -c, or #!/bin/bash) shell will exit, and finally the gnome-terminal will exit.

You can also use the Message of the Day feature, which runs after login on every terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .