1

I need to start bash in such a way that a specific alias is set. This specific alias would be

alias exit="echo Cannot exit"

This is important because I am running a program that can only run from one terminal, and I can run many of them, but only from that one terminal session. Sometimes I accidentally kill it and then all the children die. And this is a well-known modelling program, and I can't really change the way their license manager works.

Another option would be to pass a flag to this specific bash script, which would be tested in .bashrc and set the alias there. But I don't know how to do this either.

4
  • See bash's option --rcfile.
    – Cyrus
    Apr 3, 2015 at 15:19
  • .... except... my version gives me "Failed to parse arguments: Unknown option --rcfile". I am running RedHat. And yes, --rcfile does appear in the bash manpage. Strange.
    – Иван
    Apr 3, 2015 at 16:49
  • 1
    It works. Now to implement devilspie to prevent the window decoration from appearing, then I can't kill the window. askubuntu.com/questions/276847/…
    – Иван
    Apr 3, 2015 at 17:23
  • Sounds like you want to run this shell inside a screen or tmux window. Apr 3, 2015 at 22:00

2 Answers 2

1
screen -S mystupidprogram bash --rcfile ~/.bashrc-mystupidprogram

where ~/.bashrc-mystupidprogram contains

. ~/.bashrc
setopt ignoreeof
enable -n exit

Running screen (or tmux if you prefer) allows you to connect to that shell from anywhere with screen -S mystupidprogram -rd (screen calls this reattaching). To disconnect from a screen session but leave it running, which screen calls detaching, type Ctrl+A D.

0

Read the Bash manual under SHELL BUILTIN COMMANDS. You could wrap your program in a shell script that uses the builtin trap.

1
  • Actually this program requires that I start it from the cl. That is, if I want three such programs, I type the program with an ampersand three times. When I want another one, I type it again. The other three may or may not be running. So wrapping my program in a shell is technically what I want, but they all have to start from the same shell, or the license manager won't service them. I can't start three shells, in other words, so I have to start another interactive shell where I can spawn them as needed. (A little VMS there...)
    – Иван
    Apr 3, 2015 at 16:37

You must log in to answer this question.

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