Skip to main content
added 34 characters in body
Source Link
Pietru
  • 403
  • 4
  • 18

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  ("-H"|"--head")
    local -r hn="$2" ; shift 2 ;;
  ("-T"|"--tail")
    local -r tm="$2" ; shift 2 ;;

  ("--FS")                           # field separator
    local fs="$2" ; shift 2 ;;
  ("--incl")
    local incl+=("$2") ; shift 2 ;;  # file type suffix
  ("--excl")
    local excl+=("$2") ; shift 2 ;;  # file type suffix

  ("--RP")
    local pn=$2 ; shift 2 ;;
  ("--RQ")
    local qn=$2 ; shift 2 ;;

  ("--dyn"|"--dynamic")
    local dyn="1" ; shift 1 ;;
  ("-C"|"--context")
    local ctx=$2 ; shift 2 ;;

  ("-d"|"--directory")
    local fdir=$2 ; shift 2 ;;

  (--)
    shift;  break  ;;

  ...

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"  # requires original options here

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

This will call head or tail

  plist -H 8 ./01cuneus

  plist -T 13 ./01cuneus

Examples of calling pregion

plist --dyn -C 8 "Martin" ./01cuneus

plist --incl .texi --incl .org --RP 8 --RQ 13 ./01cuneus

plist --incl .texi --incl .org --dyn -C 8 "Martin" ./01cuneus

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  ("-H"|"--head")
    local -r hn="$2" ; shift 2 ;;
  ("-T"|"--tail")
    local -r tm="$2" ; shift 2 ;;

  ("--FS")                           # field separator
    local fs="$2" ; shift 2 ;;
  ("--incl")
    local incl+=("$2") ; shift 2 ;;  # file type suffix
  ("--excl")
    local excl+=("$2") ; shift 2 ;;  # file type suffix

  ("--RP")
    local pn=$2 ; shift 2 ;;
  ("--RQ")
    local qn=$2 ; shift 2 ;;

  ("--dyn"|"--dynamic")
    local dyn="1" ; shift 1 ;;
  ("-C"|"--context")
    local ctx=$2 ; shift 2 ;;

  ("-d"|"--directory")
    local fdir=$2 ; shift 2 ;;

  (--)
    shift;  break  ;;

  ...

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

This will call head or tail

  plist -H 8 ./01cuneus

  plist -T 13 ./01cuneus

Examples of calling pregion

plist --dyn -C 8 "Martin" ./01cuneus

plist --incl .texi --incl .org --RP 8 --RQ 13 ./01cuneus

plist --incl .texi --incl .org --dyn -C 8 "Martin" ./01cuneus

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  ("-H"|"--head")
    local -r hn="$2" ; shift 2 ;;
  ("-T"|"--tail")
    local -r tm="$2" ; shift 2 ;;

  ("--FS")                           # field separator
    local fs="$2" ; shift 2 ;;
  ("--incl")
    local incl+=("$2") ; shift 2 ;;  # file type suffix
  ("--excl")
    local excl+=("$2") ; shift 2 ;;  # file type suffix

  ("--RP")
    local pn=$2 ; shift 2 ;;
  ("--RQ")
    local qn=$2 ; shift 2 ;;

  ("--dyn"|"--dynamic")
    local dyn="1" ; shift 1 ;;
  ("-C"|"--context")
    local ctx=$2 ; shift 2 ;;

  ("-d"|"--directory")
    local fdir=$2 ; shift 2 ;;

  (--)
    shift;  break  ;;

  ...

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"  # requires original options here

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

This will call head or tail

  plist -H 8 ./01cuneus

  plist -T 13 ./01cuneus

Examples of calling pregion

plist --dyn -C 8 "Martin" ./01cuneus

plist --incl .texi --incl .org --RP 8 --RQ 13 ./01cuneus

plist --incl .texi --incl .org --dyn -C 8 "Martin" ./01cuneus
added 808 characters in body
Source Link
Pietru
  • 403
  • 4
  • 18

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  ("-H"|"--head")
    local -r hn="$2" ; shift 2 ;;
  ("-T"|"--tail")
    local -r tm="$2" ; shift 2 ;;

  ("--FS")                           # field separator
    local fs="$2" ; shift 2 ;;
  ("--incl")
    local incl+=("$2") ; shift 2 ;;  # file type suffix
  ("--excl")
    local excl+=("$2") ; shift 2 ;;  # file type suffix

  ("--RP")
    local pn=$2 ; shift 2 ;;
  ("--RQ")
    local qn=$2 ; shift 2 ;;

  ("--dyn"|"--dynamic")
    local dyn="1" ; shift 1 ;;
  ("-C"|"--context")
    local ctx=$2 ; shift 2 ;;

  ("-d"|"--directory")
    local fdir=$2 ; shift 2 ;;

  (--)
    shift;  break  ;;

  ...

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

This will call head or tail

  plist -H 8 ./01cuneus

  plist -T 13 ./01cuneus

Examples of calling pregion

plist --dyn -C 8 "Martin" ./01cuneus

plist --incl .texi --incl .org --RP 8 --RQ 13 ./01cuneus

plist --incl .texi --incl .org --dyn -C 8 "Martin" ./01cuneus

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  ("-H"|"--head")
    local -r hn="$2" ; shift 2 ;;
  ("-T"|"--tail")
    local -r tm="$2" ; shift 2 ;;

  ("--FS")                           # field separator
    local fs="$2" ; shift 2 ;;
  ("--incl")
    local incl+=("$2") ; shift 2 ;;  # file type suffix
  ("--excl")
    local excl+=("$2") ; shift 2 ;;  # file type suffix

  ("--RP")
    local pn=$2 ; shift 2 ;;
  ("--RQ")
    local qn=$2 ; shift 2 ;;

  ("--dyn"|"--dynamic")
    local dyn="1" ; shift 1 ;;
  ("-C"|"--context")
    local ctx=$2 ; shift 2 ;;

  ("-d"|"--directory")
    local fdir=$2 ; shift 2 ;;

  (--)
    shift;  break  ;;

  ...

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.

This will call head or tail

  plist -H 8 ./01cuneus

  plist -T 13 ./01cuneus

Examples of calling pregion

plist --dyn -C 8 "Martin" ./01cuneus

plist --incl .texi --incl .org --RP 8 --RQ 13 ./01cuneus

plist --incl .texi --incl .org --dyn -C 8 "Martin" ./01cuneus
Source Link
Pietru
  • 403
  • 4
  • 18

Bash function calling another function that requires passing user-defined options

I have a function plist that is able to call head and tail commands. But for processing regions I call a different function pregion.

# --- plist ---

  if [[ -v hn ]]; then

     head -v -hn "$n"
    
  elif [[ -v tm ]]; then

    tail -v -n "$tm"

  elif [[ -v dyn ]]; then

    pregion "$@"

  fi

With head and tail, I only use options -H, -T', --FS, and --incl. Because I am using shift when processing options, I need to have a copy ef the original plist input arguments, because I cannot simply pass "$@" to pregion.