Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove as many non POSIX idioms #27

Open
13 of 18 tasks
phyver opened this issue May 27, 2021 · 1 comment
Open
13 of 18 tasks

remove as many non POSIX idioms #27

phyver opened this issue May 27, 2021 · 1 comment
Labels
GameShell relative to GameShell code missions relative to particular missions

Comments

@phyver
Copy link
Owner

phyver commented May 27, 2021

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.

  • local variables do not exist in POSIX sh! The function mission_source relies 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

  • compgen is used in save_environment.sh. This is used to compare the before / after environments when sourcing mission files. To get variables, set can be used, but I'm not sure there is a way to get a list of functions in POSIX sh

  • find ... -print0 and xargs -0 are not in POSIX but exist in freebsd, openbsd and macos

  • sleep 0.1 isn't in POSIX but is supported in freebsd, openbsd and macos

  • readlink -f is 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.

  • mktemp isn't in POSIX, but seems to be available in freebsd, openbsd and macos
    At the moment, I only use it bare mktemp, so it would be easy to write script to do something reliable enough.

  • when not available, gettext and eval_gettext could be redefined using printf and eval+printf. (That would of course remove localization.)

  • BASHPID is used to detect subshell, but I don't know if there is a POSIX equivalent
    apparently, the POSIX way of doing it is to use sh -c 'echo $PPID', see https://unix.stackexchange.com/questions/484442/how-can-i-get-the-pid-of-a-subshell

  • $RANDOM variable : there now is a RANDOM function (using awk) to do the same

  • source FILE : can be replaced by . FILE

  • echo -n : can mostly be replaced by printf

  • read -p : can be replaced by printf ... ; read

  • read -s : was replaced by stty -echo; read; stty echo

  • $'STR': were replaced

  • the variable $OSTYPE isn'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/bin or $MISSION_DIR/bin

  • head -c and tail -c: they were replaced by instances of dd

  • the command seq is not in POSIX! (It is not present on openbsd.) It was replaced by a small script (no option are available)

@phyver phyver added GameShell relative to GameShell code missions relative to particular missions labels May 28, 2021
@phyver phyver changed the title remove as many bashisms as possible remove as many non POSIX idioms Jun 7, 2021
@phyver
Copy link
Owner Author

phyver commented Jun 15, 2021

Some work in progress can be found in branch POSIX_WIP https://github.com/phyver/GameShell/tree/POSIX_WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GameShell relative to GameShell code missions relative to particular missions
Projects
None yet
Development

No branches or pull requests

1 participant