Skip to content

Remove -i flag being passed to bash for shell mode commands #25006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

staticfloat
Copy link
Member

I do not see the benefit of passing -i to bash for shell mode commands; it reads in things like .bash_profile on some systems, and in general doesn't seem to be the right move for the quick one-off commands that shell mode is intended for. I am unable to find a program that suffers when run without the -i flag (and if it is really needed, running ;bash should give quick and easy access to those kinds of commands).

Fixes #24736
Fixes #17332

@vtjnash
Copy link
Member

vtjnash commented Dec 9, 2017

I am unable to find a program that suffers when run without the -i flag

That seems unsurprising, given that programs can't determine if they were run inside a bash with the -i flag set. On the other hand, the entire reason we are calling the shell here at all is because Stefan wanted it to source his .profile script before each command (#4659 (comment)). Although since 6e5ac65, that hasn't been entirely predictable anymore (since you may have to be prepared that the behavior will change depending on whether STDIN (which is itself distinct from the REPL input stream) is currently connected to a TTY – only a minor concern given that this is an interactive feature however).

@staticfloat
Copy link
Member Author

I personally don't think bash aliases should work inside of shell mode. Given that @StefanKarpinski thumbs-upped this PR, have you walked back on your earlier point of view? As a point of comparison, ipython doesn't source .profile.

@StefanKarpinski
Copy link
Member

Not being able to use my aliases will be annoying but this seems to fix bigger problems. We should probably introduce a pure Julia shell mode at some point anyway had have a way of introducing aliases in that instead (and maybe have tools to auto-generate them by parsing your bash scripts).

@staticfloat staticfloat merged commit d9a0049 into master Dec 12, 2017
@fredrikekre fredrikekre deleted the sf/first_remove_the_shell_from_your_own_i_before_removing_the_bash_from_your_brothers_i branch December 12, 2017 01:20
evetion pushed a commit to evetion/julia that referenced this pull request Dec 12, 2017
@montyvesselinov
Copy link

This causes a major problem. There should be work around. I need to have full access to bash in the REPL.

@montyvesselinov
Copy link

I really do not see what is the point of even having shell interface is does not reflect the user's setup.

@staticfloat
Copy link
Member Author

@montyvesselinov it would be more helpful if you could explain exactly what you need from your bash aliases in Julia shell mode. Please understand that there have been many conflicting points of view on this, and that you are not the only one who has constraints upon what you would like to see in the shell REPL mode.

@montyvesselinov
Copy link

montyvesselinov commented Oct 2, 2018

@staticfloat I need the aliases and functions defined in my bash rc files to be available in the julia shell. if they are not available i cannot perform all the shell operations. for example, if i run in parallel i would need to login to remote nodes or to use bash scripts to check the load on the remote servers. the way to do this fast is to execute bash functions/aliases in the julia shell. now i need to have a second terminal/window to do this.

in the worst case, i think there should be a flag in the julia executable or environmental variable to select the shell behavior: with or wihtout aliases/functions.

@omalled
Copy link

omalled commented Oct 11, 2018

I'm not sure if this is related to the -i flag or not, but I do find the shell behavior in 0.7 to be less pleasant than the old behavior. Here's what got my goat on 0.7:

shell> ls *jl
ls: *jl: No such file or directory

At first I thought I must be in the wrong directory before I realized what was going on. Here is how it behaves in julia 0.6 when run from the same directory:

shell> ls *jl
runtests.jl

In short, I don't really care about aliases, but it would be nice to have wildcards. I am definitely not aware of all the trade-offs that have gone into this change though.

vtjnash added a commit that referenced this pull request May 28, 2025
This was originally added as a workaround for the behavior of sh to try
to become the terminal process group leader, but no longer relevant
since #25006 removed that flag again:
```
julia> run(detach(`bash -i -c "sleep 0"`))
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
Process(`bash -i -c 'sleep 0'`, ProcessExited(0))
```

Julia recieves SIGTTOU when a process like "sh -i -c" exits (at least
for bash and zsh, but not dash, ksh, or csh), since "sh -i" sometimes
takes over the controlling terminal, causing julia to stop once the bash
process exits. This can be quite annoying, but julia goes through some
pains (in libuv) to ensure it doesn't steal the controlling terminal
from the parent, and apparently bash is not so careful about it.
However, since PR #25006, julia hasn't needed this workaround for this
issue, so we can now follow the intended behavior when the child is in
the same session group and steals the controlling terminal from the
parent. Even if such behavior seems odd, this seems to be the intended
behavior per posix design implementation that it gets SIGTTOU when julia
later tries to change mode (from cooked -> raw after printing the
prompt): http://curiousthing.org/sigttin-sigttou-deep-dive-linux.

```
$ ./julia -q
shell> bash -i -c "sleep 1"

[1]+  Stopped                 ./julia

julia> run(`zsh -i -c "sleep 0"`)
Process(`zsh -i -c 'sleep 0'`, ProcessExited(0))

julia>
[1]+  Stopped                 ./julia
```
vtjnash added a commit that referenced this pull request May 29, 2025
This was originally added as a workaround for the behavior of sh to try
to become the terminal process group leader, but no longer relevant
since #25006 removed that flag again:
```
julia> run(detach(`bash -i -c "sleep 0"`))
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
Process(`bash -i -c 'sleep 0'`, ProcessExited(0))
```

Long explanation: Julia recieves SIGTTOU when a process like "sh -i -c"
exits (at least for bash and zsh, but not dash, ksh, or csh),
since "sh -i" sometimes takes over the controlling terminal, causing
julia to stop once the bash process exits. This can be quite annoying,
but julia goes through some pains (in libuv) to ensure it doesn't steal
the controlling terminal from the parent, and apparently bash is not so
careful about it. However, since PR #25006, julia hasn't needed this
workaround for this issue, so we can now follow the intended behavior
when the child is in the same session group and steals the controlling
terminal from the parent. Even if such behavior seems odd, this seems
to be the intended behavior per posix design implementation that it
gets SIGTTOU when julia later tries to change mode (from cooked -> raw
after printing the prompt):
http://curiousthing.org/sigttin-sigttou-deep-dive-linux.

For some background on why this is a useful signal and behavior and
should not be just blocked, see nodejs/node#35536.

According to glibc, there's a half page of code for how to correctly
implement a REPL mode change call:
https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html

```
$ ./julia -q
shell> bash -i -c "sleep 1"

[1]+  Stopped                 ./julia

julia> run(`zsh -i -c "sleep 0"`)
Process(`zsh -i -c 'sleep 0'`, ProcessExited(0))

julia>
[1]+  Stopped                 ./julia
```
KristofferC pushed a commit that referenced this pull request Jun 2, 2025
This was originally added as a workaround for the behavior of sh to try
to become the terminal process group leader, but no longer relevant
since #25006 removed that flag again:
```
julia> run(detach(`bash -i -c "sleep 0"`))
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
Process(`bash -i -c 'sleep 0'`, ProcessExited(0))
```

Long explanation: Julia recieves SIGTTOU when a process like "sh -i -c"
exits (at least for bash and zsh, but not dash, ksh, or csh),
since "sh -i" sometimes takes over the controlling terminal, causing
julia to stop once the bash process exits. This can be quite annoying,
but julia goes through some pains (in libuv) to ensure it doesn't steal
the controlling terminal from the parent, and apparently bash is not so
careful about it. However, since PR #25006, julia hasn't needed this
workaround for this issue, so we can now follow the intended behavior
when the child is in the same session group and steals the controlling
terminal from the parent. Even if such behavior seems odd, this seems
to be the intended behavior per posix design implementation that it
gets SIGTTOU when julia later tries to change mode (from cooked -> raw
after printing the prompt):
http://curiousthing.org/sigttin-sigttou-deep-dive-linux.

For some background on why this is a useful signal and behavior and
should not be just blocked, see nodejs/node#35536.

According to glibc, there's a half page of code for how to correctly
implement a REPL mode change call:
https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html

```
$ ./julia -q
shell> bash -i -c "sleep 1"

[1]+  Stopped                 ./julia

julia> run(`zsh -i -c "sleep 0"`)
Process(`zsh -i -c 'sleep 0'`, ProcessExited(0))

julia>
[1]+  Stopped                 ./julia
```

(cherry picked from commit 0cbe466)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants