I want to run a bash subshell, (1) run a few commands, (2) and then remain in that subshell to do as I please. I can do each of these individually:
Run command using
-c
flag:$> bash -c "ls; pwd; <other commands...>"
however, it immediately returns to the "super" shell after the commands are executed. I can also just run an interactive subshell:
Start new
bash
process:$> bash
and it won't exit the subshell until I say so explicitly... but I can't run any initial commands. The closest solution I've found is:
$> bash -c "ls; pwd; <other commands>; exec bash"
which works, but not the way I wanted to, as it runs the given commands in one subshell, and then opens a separate one for interaction.
I want to do this on a single line. Once I exit the subshell, I should return back to the regular "super"shell without incident. There must be a way~~
NB: What I am not asking...
- not asking where to get a hold of the bash man page
- not asking how to read initializing commands from a file... I know how to do this, it's not the solution I'm looking for
- not interested in using tmux or gnu screen
- not interested in giving context to this. I.e., the question is meant to be general, and not for any specific purpose
- if possible, I want to avoid using workarounds that sort of accomplish what I want, but in a "dirty" way. I just want to do this on a single line. In particular, I don't want to do something like
xterm -e 'ls'
exec bash
solution unsuitable for you? – glenn jackman Mar 9 '12 at 16:21exec bash
solution involves two separate subshells. I want one continuous subshell. – SABBATINI Luca Mar 9 '12 at 19:18exec
is that it replaces the first subshell with the second, so you're only left 1 shell below the parent. If your initialization commands set environment variables, they will exist in the exec'ed shell. – glenn jackman Mar 9 '12 at 19:45exec
is that you lose anything that's not passed down to subshells via the environment, such as non-exported variables, functions, aliases, ... – cjs Sep 15 '18 at 3:49