Want more features on Pastebin? Sign Up, it's FREE!
Guest

Bash Lambda

By: a guest on May 8th, 2014  |  syntax: Bash  |  size: 0.31 KB  |  views: 753  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. lambda()
  2. {
  3.         # Save orignal function
  4.         local ORIGINAL=$(declare -f otl)
  5.         local SHIFT_SIZE=${1}
  6.         shift
  7.         local vars=()
  8.  
  9.         for ((i=0;i<${SHIFT_SIZE};i++)); do
  10.                 vars+=(${1})
  11.                 shift
  12.         done
  13.  
  14.         eval "otl() { $@; }"
  15.         otl ${vars[@]}
  16.         unset -f otl
  17.         eval "${ORIGINAL}"
  18. }
  19.  
  20. lambda 3 ro sham bo 'echo $3 $2 $1'
clone this paste RAW Paste Data