1. 31
  1. 12

    This list does not mention the most surprising (and a bit disturbing) bash feature for me: it can open tcp/udp sockets on its own [0] through a feature called “special redirects” (there’s no actual filesystem involved here):

    $ (exec 3<>/dev/tcp/www.google.com/80 ; 
    echo "GET /search?q=bash+madness HTTP/1.0" >&3; 
    echo >&3; 
    cat <&3 ) | less

    [0] https://dmytrish.net/blog/en/bash-tcp

    1. 2

      I scanned over this, and OSH [1] should support basically everything here. If it doesn’t, feel free to file a bug!


      Hm now that I look more at the repo, it looks like this would be a good test: https://github.com/dylanaraps/pure-bash-bible/blob/master/test.sh

      [1] http://www.oilshell.org/blog/2018/07/23.html

      1. 2

        Lots of things can already be done with portable sh code. typeset for example is quite powerful but mentioned nowhere in the repo:

        $ var=VaL; typeset -l lvar=$var; typeset -u uvar=$var
        $ echo $lvar $uvar
        val VAL

        In fact, this builtin is often wrapped by the shell itself, at least in OpenBSD’s ksh:

        $ alias | fgrep typeset
        autoload='typeset -fu'
        functions='typeset -f'
        integer='typeset -i'
        1. 2

          typeset is not posix

          • posix sh has no way to do what typeset -f does
          • bash has no way to do what typeset -fu does in your ksh
          • typeset -i doesn’t really have the same effect in bash and ksh
          • the posix way to convert a string to lowercase/uppercase involves tr or awk
          • most popular shells support local, but it’s not posix either

          “portable sh code” != “it works on my openbsd”

          1. 1

            Note how I did not speak of POSIX; you mistake the ksh example as general assumption. My reply to pl’s comment tells you what I meant with “portable” (admittedly, wording was a bit misleading).

            1. 1

              what’s your definition of portable?

          2. 1

            What do you mean with portable sh code? I just tried it with dash and it has no typeset built in.

            1. 2

              At least available in Bourne and Korn shell derivatives; (Debian’s) Almquist Shell does not implement that particular builtin.

          Stories with similar links:

          1. pure bash bible: A collection of pure bash alternatives to external processes via cfenollosa 3 years ago | 41 points | 13 comments