SHARE
TWEET

line_x

amphoterrific Aug 14th, 2019 (edited) 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # vim:ft=zsh fdc=0 nuw=2
  2. ## read one or more lines of a file and execute it as a command
  3. #
  4. # intended to be loaded as a shell function
  5. # so that anthing executed will effect the current environment
  6. # no clue if this will work in shells other than zsh without modification
  7. #
  8. ## input can be '1 file' '1,4 file' or '1 3 5 file'
  9. #
  10. local TMP=.${$}linex
  11. if [[ "${#}" -gt 2 ]]; then ## test if input is multiple non consecutive lines
  12.     for X in ${*[1,-2]}; do ## run each specified line as a seperate command
  13.         eval $(sed -n ${X}p ${*[-1]})
  14.     done
  15.     return
  16. else ## write the specified range to a tmp file, then source that file
  17.     sed -n "${1}p" "${2}" >$TMP
  18.     source $TMP
  19.     rm $TMP
  20.     return
  21. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top