Flag at command line bash shell

Asked

Viewed 146 times

1

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

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
  • So far I have this and when I run the command still does not sort the output, in this case a set of links target="$1"; wget -qO- "http://reddit.com/r/${target}" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*"

case"$1" in
 -r) pp="shuf" ;;
 -s) pp="sort" ;;
 *) pp="cat -n" ;;
esac

Browser other questions tagged

You are not signed in. Login or sign up in order to post.