Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke bash, run commands inside the new shell, and then give control back to user?

Tags:

bash

shell

This must either be really simple or really complex, but I couldn't find anything about it... I am trying to open a new bash instance, then run a few commands inside it, and give the control back to the user inside that same instance.

I tried:

$ bash -lic "some_command" 

but this executes some_command inside the new instance, then closes it. I want it to stay open.

One more detail which might affect answers: if I can get this to work I will use it in my .bashrc as alias(es), so bonus points for an alias implementation!

like image 440
Félix Saparelli Avatar asked Aug 19 '11 10:08

Félix Saparelli


People also ask

How do I invoke bash?

In order to run a Bash script on your system, you have to use the “bash” command and specify the script name that you want to execute, with optional arguments. Alternatively, you can use “sh” if your distribution has the sh utility installed.

How do you echo a command in shell script?

The echo command writes text to standard output (stdout). The syntax of using the echo command is pretty straightforward: echo [OPTIONS] STRING... Some common usages of the echo command are piping shell variable to other commands, writing text to stdout in a shell script, and redirecting text to a file.


1 Answers

bash --rcfile <(echo '. ~/.bashrc; some_command') 

dispenses the creation of temporary files. Question on other sites:

  • https://serverfault.com/questions/368054/run-an-interactive-bash-subshell-with-initial-commands-without-returning-to-the
  • https://unix.stackexchange.com/questions/123103/how-to-keep-bash-running-after-command-execution