Debe iniciar explícitamente un shell interactivo bash
al final de su secuencia de comandos para mantener la ventana abierta cuando abra el archivo .command
desde el Finder.
La siguiente revisión de su script lo demuestra y también agiliza otros aspectos de su código:
#!/bin/bash
# Note: $PATH already exists as an exported variable, assigning to it
# again preserves that status, so there's no need to call 'export' below.
# Adding CMake to Path
PATH+=:/Users/Shared/CMake/CMake.app/Contents/bin/
# Adding Ninja to Path
PATH+=:/Users/Shared/Ninja/
# Adding GCC to Path
PATH+=:/usr/local/gcc-8.2/bin/
cat <<EOF
Path updated to:
$PATH
Starting interactive Bash shell...
EOF
# Start an interactive Bash shell that inherits this script's environment
# and keeps the window open.
# Using -l makes the interactive shell a login shell, which makes it
# load the same initialization files as shells created by Terminal.app,
# notably, ~/.bash_profile
# Be sure that ~/.bash_profile doesn't override $PATH.
exec bash -l
Este archivo .command
también se abrirá desde una ventana terminal existente, pero tenga en cuenta que ingresará un shell secundario interactivo - exit
ing desde ese shell secundario regresa a ti al original.
Es posible modificar su secuencia de comandos de modo que si lo invoca desde una ventana de terminal (shell) existente, modifique el entorno de la shell directamente , pero luego tendrá que source
/ .
el script en la invocación (por ejemplo, . ./script.command
):
#!/bin/bash
# Note: $PATH already exists as an exported variable, assigning to it
# again preserves that status, so there's no need to call 'export' below.
# Adding CMake to Path
PATH+=:/Users/Shared/CMake/CMake.app/Contents/bin/
# Adding Ninja to Path
PATH+=:/Users/Shared/Ninja/
# Adding GCC to Path
PATH+=:/usr/local/gcc-8.2/bin/
# Determine if this script is being sourced.
[[ $0 != "$BASH_SOURCE" ]] && sourced=1 || sourced=0
cat <<EOF
Path updated to:
$PATH
EOF
if (( sourced )); then # sourced from the calling shell.
# The calling shell's environment has been modified - nothing more to do.
:
else # otherwise: launched from Finder or from a terminal without sourcing
# A new interactive shell must be launched for the environment modifications
# to take effect and, if launched from Finder, to keep the terminal window
# open.
echo "Starting new interactive Bash shell with modified environment..."
# Using -l makes the interactive shell a login shell, which makes it
# load the same initialization files as shells created by Terminal.app,
# notably, ~/.bash_profile
# Be sure that ~/.bash_profile doesn't override $PATH.
exec bash -l
fi