setup-env.csh: Harden for people who like aliases (#49670)

A user had `grep` aliased to `grep -n`, which was causing `csh` setup to
fail due to number prefixes in `SPACK_ROOT`.

- [x] Prefix invocations of `grep` and `sed` (which are not builtin) with `\`
      to avoid any aliases.
- [x] Avoid using `dirname` altogether -- use csh's `:h` modifier (which does
      the same thing) instead.

Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
This commit is contained in:
Todd Gamblin 2025-03-25 09:01:28 -07:00 committed by GitHub
parent 2ced87297d
commit 20ddb85020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,14 +33,15 @@ endif
# filter this script out of list of open files # filter this script out of list of open files
if ( $?_sp_lsof ) then if ( $?_sp_lsof ) then
set _sp_source_file = `$_sp_lsof | sed -e 's/^[^/]*//' | grep "/setup-env.csh"` set _sp_source_file = `$_sp_lsof | \sed -e 's/^[^/]*//' | \grep "/setup-env.csh"`
endif endif
# This script is in $SPACK_ROOT/share/spack; get the root with dirname # This script is in $SPACK_ROOT/share/spack.
# Get the root with :h, which is like dirname but it's a csh builtin
if ($?_sp_source_file) then if ($?_sp_source_file) then
set _sp_share_spack = `dirname "$_sp_source_file"` set _sp_share_spack = "$_sp_source_file:h"
set _sp_share = `dirname "$_sp_share_spack"` set _sp_share = "$_sp_share_spack:h"
setenv SPACK_ROOT `dirname "$_sp_share"` setenv SPACK_ROOT "$_sp_share:h"
endif endif
if (! $?SPACK_ROOT) then if (! $?SPACK_ROOT) then
@ -73,8 +74,8 @@ _spack_pathadd PATH "$SPACK_ROOT/bin"
eval `spack --print-shell-vars csh` eval `spack --print-shell-vars csh`
# Set up module search paths in the user environment # Set up module search paths in the user environment
set tcl_roots = `echo $_sp_tcl_roots:q | sed 's/:/ /g'` set tcl_roots = `echo $_sp_tcl_roots:q | \sed 's/:/ /g'`
set compatible_sys_types = `echo $_sp_compatible_sys_types:q | sed 's/:/ /g'` set compatible_sys_types = `echo $_sp_compatible_sys_types:q | \sed 's/:/ /g'`
foreach tcl_root ($tcl_roots:q) foreach tcl_root ($tcl_roots:q)
foreach systype ($compatible_sys_types:q) foreach systype ($compatible_sys_types:q)
_spack_pathadd MODULEPATH "$tcl_root/$systype" _spack_pathadd MODULEPATH "$tcl_root/$systype"