On Sunday, 19 July 2020 at 19:16:29 UTC, jmh530 wrote:
I just upgraded a machine to Linux Mint 20 on a fresh install and tried to run the install script. It fails with
main: line 178: USERPROFILE: unbound variable

This line should only be called on Windows, which I found strange. It turns out that this is driven by

```
posix_terminal() {
# If this script is run on Windows cmd by passing it as argument to bash.exe, # the shell level will be 1. If it is run from a POSIX terminal, it will be > 1.
    if [ "$SHLVL" = 1 ]; then
        false
    else
        true
    fi
}
```

Running `echo $SHLVL` prints `1`

Running
```
bash
echo $SHLVL
```
prints `2`


Running `echo $SHELL` prints `/bin/bash`

The issue seems to be related to an update to Ubuntu 16:
https://askubuntu.com/questions/856532/why-is-shlvl-initially-2-in-ubuntu-16-10-but-not-earlier-versions

I don't think it is related to the Ubuntu 16.10 issue, because the above test does not rely on SHLVL being 2 initially. If the script is called from the terminal, and the terminal is running bash (which it seems to do according to the output of $SHELL) SHLVL should be at least 1 on the terminal and one higher when the script is run (since running a script starts a new bash). Maybe the script is run in a way that breaks this assumption? Is it run using `call`? Is it run headless, without a terminal? Is it not run by real bash?

There is a related conversation here, but not quite the same: https://github.com/dlang/installer/commit/e084815001390538bbd6fe5be7c2d4d81ee681b7#commitcomment-40487617

Please open an issue on https://issues.dlang.org/enter_bug.cgi and post a link here, if we need to drill deeper.

I can imagine that the current `posix_terminal()` is flawed if the terminal is running a shell that is not bash, for which we should find a solution.

--Bastiaan.

Reply via email to