Home > Enterprise >  How not to terminate after carried out commands in bash
How not to terminate after carried out commands in bash

Time:10-20

After carrying out commands with "-c" option of bash, how can I make the terminal wait for input while preserving the environment?

Like CMD /K *** or pwsh -NoExit -Command ***.

CodePudding user response:

From a comment by Cyrus:

You can achieve something similar by abusing the --rcfile option:

bash --rcfile <(echo "export PS1='> ' && ls")

From bash manpage:

--rcfile file

Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive

This is the answer I was looking for. Thank you!!

As an example of use, I use the following method to use the latest docker image with my preferred repository without building the image:

docker run --rm -it ubuntu:22.04 bash -c "bash --rcfile <(echo 'sed -i -E '\''s%^(deb(-src|)\s )https?://(archive|security)\.ubuntu\.com/ubuntu/%\1http://mirrors.xtom.com/ubuntu/%'\'' /etc/apt/sources.list && apt update')"
  •  Tags:  
  • bash
  • Related