I am hoping this appears at https://pubs.opengroup.org/onlinepubs/9699919799/ soon. This is the link I use most often to go through the specification. In fact, I owe a lot of my shell scripting skills to this online resource. As a specific example, the seemingly simple matter of when the shell decides to split a string based on $IFS and when it does not were quite confusing to me until I went through the specificatio…
I think many people are even more surprised by this: x=$a # not split! It means the same thing as x="$a" They were taught that you have to quote everything, which is a reasonable rule to follow, but it's not true. --- I never wrote about this on the Oils blog ( https://www.oilshell.org/ ), but the post would be titled: Shell Has Context Sensitive Evaluation Basically the two contexts you should think of are: (1) EVAL…
Posix.1-2024 is published
71–80 of 87 posts
Re: Posix.1-2024 is published
#72Earlier quoted context omitted.
With all due respect, you don't seem to understand what POSIX is.
I appreciate your respect. Can you contrast POSIX with IRC and explain why IRC can work on the web but POSIX can't? https://ircv3.net/specs/extensions/websocket
Re: Posix.1-2024 is published
#73Earlier quoted context omitted.
Prefer `#!/usr/bin/env bash` instead, since /bin/bash isn't a standardized location for bash (even across Linux distros). The former causes $PATH to be searched for bash.
This is pretty common advice but I think it is fighting the previous war. This idea is useful for virtualenv-type tricks if you want to ensure use of your personal version of the interpreter on a shared system, but you have to boil an ocean of scripts. You don't know if you caught them all. Docker won instead - a quick filesystem namespace comprehensively catches everything. Just use #!/bin/bash. EDIT: I was thinking…
Re: Posix.1-2024 is published
#74Earlier quoted context omitted.
Prefer `#!/usr/bin/env bash` instead, since /bin/bash isn't a standardized location for bash (even across Linux distros). The former causes $PATH to be searched for bash.
Is /usr/bin/env a standardized location?
Re: Posix.1-2024 is published
#75Earlier quoted context omitted.
Prefer `#!/usr/bin/env bash` instead, since /bin/bash isn't a standardized location for bash (even across Linux distros). The former causes $PATH to be searched for bash.
Is /usr/bin/env a standardized location?
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...
POSIX omits from standardisation what is not necessary for an application to work, so that a wide range of systems can be supported. As for Shebang, it can be rewritten in the installation script and is therefore considered an area of system administration.
Re: Posix.1-2024 is published
#76Earlier quoted context omitted.
> Aren't people targetting bash or basic bourne shell features intead of posix? I know many banks still have AIX systems with shells like ksh89, ksh93, etc. as the default shell. So if a shell script is written to work with a POSIX shell (instead of a particular shell), it has a better chance of running on such systems. Also, on Debian, the default non-interactive shell is dash [1]. This is the Debian Almquist Shell…
> So again, if we write system scripts for Debian and want it to run on Debian without any hassle, it makes sense to write the scripts to conform to POSIX shell. Or explicitly use bash in your shebang. One of the problems with Bash is that it insists on doing bash -y things even when you tell it to act like sh . People ask why you should write (or at least test) code to be multi-platform (even the basics of running i…
Its behaviour is a common behaviour of all sh, not just Bash.
Re: Posix.1-2024 is published
#77Where is POSIX actually useful today? Is it mostly for shell scripts? Aren't people targetting bash or basic bourne shell features intead of posix? Is shellcheck checking for best practices instead of POSIX compliance? And for other applications (GUI, servers, etc) strict POSIX compliance might be too restrictive? And with many things being Linux (or Linux-like like WSL) the need for this might be less? Are Android a…
Re: Posix.1-2024 is published
#78Did we get `local`?
Sadly no. That's one of the few things that can't be done with, but semantics can subtly vary between implementation. Which is why I do a runtime check for them: https://git.sr.ht/~q3cpma/scripts/tree/b4b3c62f6a77828d0c445...
if command -v command >/dev/null 2>&1
then command -v local >/dev/null 2>&1 || alias local=typeset
fi
eval "__fn=;__fn(){ local __fn=leak;};__fn || :;"
if test -n "$__fn"
then echo local leaks here!
fi
It will not crash on posh because I'm being tricky with eval and command. posh supports local variable scope.The only shell partially missing local support is ksh, but it has a gotcha. It works if the function is declared with the `function` keyword. All you have to do is use ksh's own tools to redeclare all functions automatically:
__list=$(typeset +f)
IFS="$__eol" # __eol should have a line break
for __decl in $__list
do
__name=${__decl%" #"*}
__name=${__name%"()"}
__body="$(typeset -f "$__name" || :)"
eval "function $__name ${__body#"$__decl"}"
done
IFS=" "
Of course, for this to work, all functions must be loaded before running and any declared after the fix will not be local, which is a good idea anyway. I always put the alias polyfill on the header of my library and the eval/for polyfill just before invoking my main function.There is still an inconsistency with default local values. To get the same behavior everywhere, always initialize local variables
THIS IS FINE:
local foo=;
local foo=bar;
THIS CAN INHERIT WEIRD STUFF: local foo;
Done, you have portable bourne sh scope everywhere imaginable.Re: Posix.1-2024 is published
#79wasm support?
Re: Posix.1-2024 is published
#80Earlier quoted context omitted.
webrtc, ws, postmessage?
Those aren't part of Wasm. WebRTC and WebSockets both predate Wasm by 6 years, and neither require Wasm to work. postMessage is part of Web Workers, also separate frow Wasm. I'll ask again, what would it mean for POSIX to "support" Wasm?