blmayer/ereandel

BUG: Does not play well with Unix systems

Closed this issue · 19 comments

I am on Void Linux, I am running Void without GNU coreutils, that might sound strange, but is really simple, I built toybox, then ubase, and then sbase and put all that into /usr/local/bin. Then I progressively started to get rid of GNU packages. So I guess your program is using non-standard functions of printf or echo. GNU adds tons of things to the coreutils, it is easy to mistake them for being standard, they are not, they should clarify what is an extension and what is strictly POSIX but they do no. Anyways, here is the problem:

image

\e[?25l        Circumlunar Gemini Outpost
\e[m        
\e[m        Project Gemini has moved!!!
\e[m        
\e[m        This server, gemini.circumlunar.space, is no longer the official home of Project Gemini!  The official 
\e[m        protocol specification, FAQ and other documentation now lives at geminiprotocol.net:
\e[m        
\e[m        1 =>  gemini://geminiprotocol.net New official Project Gemini capsule
\e[m        
\e[m        Please update your bookmarks, your subscription to the news feed, and any links to the project capsule in 
\e[m        your content!
\e[m        
\e[m        CAPCOM aggregator
\e[m        
\e[m        This server hosts the first Gemini content aggregator, CAPCOM.
\e[m        
\e[m        2 =>  capcom/ CAPCOM
\e[m        
\e[m        Free Gemini hosting
\e[m        
\e[m        In the earlier stages of Project Gemini, free hosting was provided at this server.  The offer has been 
\e[m        discontinued for new users, but existing accounts remain open and content remains online.
\e[m        
\e[m        3 =>  users/ Users with Gemini content on this server
\e[musage: od [-bdosvx] [-A addressformat] [-E | -e] [-j skip] [-t outputformat] [file ...]

Thanks for reporting this. I'll try to reproduce the error

I changed some echo calls on 30574fd. Can you check if it works for you?

image

GNU has some packages and tools where they do not completely tell you if the flags are an addition of them or part of the standard Unix tool's options.

For example, I have 4 sets of coreutils installed, the ones I use are those from Toybox, the better and more POSIX of them all is obviously SBase, since its source code contains rewritten parts of the original Unix Research OS and some bits from Plan9.

As you can see, avoiding GNU entirely would make the script work not only on Linux but also any other POSIX OS. I recommend you just try downloading the toybox binaries and put them in a folder and add it to your PATH, that way you can be certain your script works on oBSD for example. Anyways, thanks for the awesome browser, I do use it in my others OSes.

I forgot to paste this:

[anto@beef ~]$ /usr/bin/cat --help
Usage: /usr/bin/cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
      --help        display this help and exit
      --version     output version information and exit

Examples:
  /usr/bin/cat f - g  Output f's contents, then standard input, then g's contents.
  /usr/bin/cat        Copy standard input to standard output.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/cat>
or available locally via: info '(coreutils) cat invocation'
[anto@beef ~]$ /opt/altsys/bin/cat --help
Toybox 0.8.10 multicall binary (see toybox --help)

usage: cat [-etuv] [FILE...]

Copy (concatenate) files to stdout.  If no files listed, copy from stdin.
Filename "-" is a synonym for stdin.

-e	Mark each newline with $
-t	Show tabs as ^I
-u	Copy one byte at a time (slow)
-v	Display nonprinting characters as escape sequences with M-x for
	high ascii characters (>127), and ^x for other nonprinting chars
[anto@beef ~]$ /portstree/homebrew/sbase/cat --help
usage: /portstree/homebrew/sbase/cat [-u] [file ...]
[anto@beef ~]$ 

There, you can see just how widely different the implementations are. GNU just does not care about POSIX at all(they also do not respect the ISO C specification).

[anto@beef ~]$ /usr/bin/md5sum --help
Usage: /usr/bin/md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.

With no FILE, or when FILE is -, read standard input.
  -b, --binary          read in binary mode
  -c, --check           read checksums from the FILEs and check them
      --tag             create a BSD-style checksum
  -t, --text            read in text mode (default)
  -z, --zero            end each output line with NUL, not newline,
                          and disable file name escaping

The following five options are useful only when verifying checksums:
      --ignore-missing  don't fail or report status for missing files
      --quiet           don't print OK for each successfully verified file
      --status          don't output anything, status code shows success
      --strict          exit non-zero for improperly formatted checksum lines
  -w, --warn            warn about improperly formatted checksum lines

      --help        display this help and exit
      --version     output version information and exit

The sums are computed as described in RFC 1321.
When checking, the input should be a former output of this program.
The default mode is to print a line with: checksum, a space,
a character indicating input mode ('*' for binary, ' ' for text
or where binary is insignificant), and name for each FILE.

Note: There is no difference between binary mode and text mode on GNU systems.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/md5sum>
or available locally via: info '(coreutils) md5sum invocation'

[anto@beef ~]$ /opt/altsys/usr/bin/md5sum --help
Toybox 0.8.10 multicall binary (see toybox --help)

usage: ???sum [-bcs] [FILE]...

Calculate hash for each input file, reading from stdin if none, writing
hexadecimal digits to stdout for each input file (md5=32 hex digits,
sha1=40, sha224=56, sha256=64, sha384=96, sha512=128) followed by filename.

-b	Brief (hash only, no filename)
-c	Check each line of each FILE is the same hash+filename we'd output
-s	No output, exit status 0 if all hashes match, 1 otherwise
[anto@beef ~]$ 

Thanks for the output. Can you paste your astro config file here, please?

I didn't modify it at all

I advise you use printf if you want this to be POSIX, or just use #!/bin/bash instead if this is not supposed to work on other POSIX systems apart from Linux.

Sorry, it might have something to do with using SH? Some OSes implement SH differently... Some link SH to Bash, which is wrong, I remembered that and tried using bash as shebang, now it works... It seems your script uses bash's internal echo command.

I changed all printf calls to use toybox's printf and it worked here. I think it is related to the shell, as you said. I'll try using a different shell. I think there is some flag I can pass to only use POSIX features.

Or your terminal emulator

Yeah, you might have success with KSH93. I use KSH to write my scripts and then change the shebang to sh or dash. That way I ensure POSIX compatibility, anyways, cool project!

Thanks. I tested using dash and toybox, everything looks fine. I think this is your terminal emulator. What's it?

xfce4 terminal, but it worked with bash and it didn't work with dash for me.

Hi, just confirming here I had the exact same problem on latest commit astro 0.25.0 (and am also on Void linux!), but when i edited the shebang to bash it worked fine.

Thanks. I'll check xfceterm this week.

After seeing this article I changed some escape sequences is latest commit. Can you take a look?

Confirming, that fixed it for me! Thank you.

Wonderful. Gonna release this fix. Thanks for the help.