Put flag at bash shell command line

1

I'm trying to put a flag that can sort or shuffle the output, but I could only do that in code and intended it to work when I put the flag on the command to run the file, for example ./bash.sh -r .

    
asked by anonymous 02.01.2018 / 22:34

1 answer

0

A small example:

#!/bin/bash

case $1 in                ## definir o pósprocessador
  -r)  pp="shuf" ;;         # -r    shuffle 
  -s)  pp="sort" ;;         # -s    sort
   *)  pp="cat -n"  ;;      # default numera linhas
esac

function proc(){
  ls /bin                 ## ... produzir um output
}

proc | $pp
    
06.01.2018 / 12:48