J418F

                  Learn You a Haskell for Great Good
                  Miran Lipovaca
                  No Starch Press, Inc. 2011

## SH ..ORT INTRO.

  1. Unix commands (first 50) and redirections < | > >>

  2. # this is a comment
     continue on next line:  \
     two or more commands on the same line: x="cheese"; echo $x
     string is the only data type
     quotation '' (strong) "" (weak) `` (execute)
     concatenate  echo "SAY$CHEESE"

  3. expressions

       numeric $((..))
       strings expr (match substr index length)

  4. variables

       write like vvv=HELLO
       read like $vvv
       volatile (hävimälu) and non-volatile (säilmälu)
       internal variables: $? $# $0..$9 $RANDOM .. there is more
         $ test 1 -lt 2; echo $?
         0
         $ test 1 -gt 2; echo $?
         1

  5. functions

       foo() {
         echo $1
       }
       foo $i

  6. flow control

       if
       then else
         test (-a -o -lt -le -eq -ge -gt -ne -e (exists) there are more)
       fi

       for while seq ..
         do
         done

       case EXPRESSION in
         CASE1|CASE2) COMMAND-LIST ;;
         ..
         CASEN) COMMAND-LIST;;
       esac

     A longer case story (and more) is here:

      https://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_03.html

  7. arrays

     The one and only data type is the string. String consists of characters.

EXAMPLE 1. Arrays

SH (Does not have native arrays):

  #!/bin/sh
  a="stone tree pond lake river meadow hill bushes sand cave"
  for s in `echo $a`; do echo $s; done

Or BASH:

  #!/bin/bash
  a=(stone tree pond lake river meadow hill bushes sand cave)
  for s in "${a[@]}"; do echo $s; done

EXAMPLE 2. Display the line of space separated 10 random integer numbers between 0..100 . Sort them in ascending order.

Test building blocks:

  # a="1 2 3"; x=`expr match "$a" .*2`; test $x -gt 0; echo $?
  # x=$(($RANDOM%100)); echo $x
  # x=1; if test $x -gt 0; then echo CHEESE; fi

Now put things together:

  #!/bin/bash

  c=0
  a=""
  while test $c -lt 10
  do
    n=$(($RANDOM%100))
    x=`expr match "$a" ".*$n"`
    if test $x -eq 0
    then
      a=$a$n" "
      c=$(($c+1))
    fi
  done
  echo $a | tr \\040 \\n | sort -n | tr \\n \\040
  echo

Or just

  $ shuf -i 0-100 -n 10 | sort -n | tr '\n' ' ' ; echo


## Annex A. english words used and their translations:

  1. Pick a word list:

    $ cat this_file | tr '\n' ' ' | sed 's/[0..9.,;!?_ ]\+/[ ]/' | \
      tr ' ' '\n' | grep '^[a-zA-Z]\+$' | sed 's/\(.\)/\L\1/' | \
      sort | uniq

  2. translate them online using, say:

     https://translate.google.com/
