Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make bash run a command right after it starts and then stay in this session?

Tags:

bash

I need to run the command right after the bash starts and then stay in the session. I was expecting something like that would work bash && cd ~/Work, but, apparentely, it would run the second command in the initial session, not the one I'm starting.

I've found this run bash command in new shell and stay in new shell after this command executes thread, but running bash --rcfile doesn't work for me, because I still need the rcfile to be loaded.

like image 637
snitko Avatar asked Jan 09 '12 06:01

snitko


People also ask

Does Bash wait for command to finish?

The bash WAIT command is used to halt the execution of a script until all background jobs or specified JobID/PIDs terminate successfully and return an expected exit code to trigger the next command that was “waited for.”

How do I run a shell script in interactive mode?

You run the shell script (pure. bat on Windows and pure on Linux®) from the pure. cli/bin directory on your local computer. In this procedure you start in interactive mode, specifying the host name or IP address for the system, along with an authorized user ID and password to start a user session.


1 Answers

You can still use --rcfile, you just need to include the sourcing of the default rc file in your command list:

bash --rcfile <(echo ". ~/.bashrc && cd ~/Work")
like image 123
Carl Norum Avatar answered Nov 15 '22 05:11

Carl Norum