OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.66k stars 2.46k forks source link

`scripts/setdevenv.sh` kills the shell #10157

Open eschnett opened 1 month ago

eschnett commented 1 month ago

What is the bug?

The setdevenv.sh script contains code to check whether it is called or sourced by the shell:

called=$_

if [[ $BASH_VERSION && $(realpath $called) == $(realpath "$0") ]]; then
    echo "Script should be sourced with '. $0', instead of run."
    exit 1
fi

This test fails for me for two reasons:

Steps to reproduce the issue

I source the script via

cd build
(. ../scripts/setdevenv.sh)

Versions and provenance

Current master branch as of today

Additional context

No response

rouault commented 1 month ago
  • The shell is called -bash, with a leading hyphen,

how come ? which environment leads to that? (I suck at shell scripting, so I'm unlikely to be able to fix that)

eschnett commented 1 month ago

When a shell acts as login shell, then its $0 is modified to start with a dash.

See e.g. https://www.man7.org/linux/man-pages//man1/bash.1.html, section "SHELL BUILTIN COMMANDS", entry for "exec": "If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command."