-
Notifications
You must be signed in to change notification settings - Fork 180
Description
There are several bashisms in GameShell code.
I am trying to remove some of them, more as a learning experience than as a real goal. (Even though it would make it easier to port GameShell to zsh or some other shell.)
All of this concerns primarily GameShell's code, but missions' code could also benefit from them where appropriate.
-
localvariables do not exist in POSIXsh! The functionmission_sourcerelies on them to be re-entrant. There might be some ideas here: htps://stackoverflow.com/questions/18597697/posix-compliant-way-to-scope-variables-to-a-function-in-a-shell-script -
compgenis used insave_environment.sh. This is used to compare the before / after environments when sourcing mission files. To get variables,setcan be used, but I'm not sure there is a way to get a list of functions in POSIXsh -
find ... -print0andxargs -0are not in POSIX but exist in freebsd, openbsd and macos -
sleep 0.1isn't in POSIX but is supported in freebsd, openbsd and macos -
readlink -fis not in POSIX and doesn't work on macos. I wrote a small script, but it doesn't mix well when intermediate directories don't have the execute bit. -
mktempisn't in POSIX, but seems to be available in freebsd, openbsd and macos
At the moment, I only use it baremktemp, so it would be easy to write script to do something reliable enough. -
when not available,
gettextandeval_gettextcould be redefined usingprintfandeval+printf. (That would of course remove localization.) -
BASHPIDis used to detect subshell, but I don't know if there is a POSIX equivalent
apparently, the POSIX way of doing it is to usesh -c 'echo $PPID', see https://unix.stackexchange.com/questions/484442/how-can-i-get-the-pid-of-a-subshell -
$RANDOMvariable : there now is aRANDOMfunction (usingawk) to do the same -
source FILE: can be replaced by. FILE -
echo -n: can mostly be replaced byprintf -
read -p: can be replaced byprintf ... ; read -
read -s: was replaced bystty -echo; read; stty echo -
$'STR': were replaced -
the variable
$OSTYPEisn't necessary anymore since almost every problematic function has been re-implemented in a POSIX compliant way -
export -f: it can mostly be replaced by writing an external script in$GSH_ROOT/binor$MISSION_DIR/bin -
head -candtail -c: they were replaced by instances ofdd -
the command
seqis not in POSIX! (It is not present on openbsd.) It was replaced by a small script (no option are available)