Quantcast
Viewing all articles
Browse latest Browse all 7

Answer by Ciro Santilli 新疆改造中心法轮功六四事件 for How to execute consecutive commands from history?

fc for loop and xsel

This works well when I want to concatenate and re-run the last n commands multiple times:

fcn() (
  from="${1:-2}"
  to="${2:-1}"
  if [ "$from" -ne "$to" ]; then
    for i in `seq "$from" -1 "$(($to + 1))"`; do
      printf "$(fc -ln -${i} -${i}) && "
    done
  fi
  printf "$(fc -ln -${to} -${to})"
)

Then:

$ echo a
a
$ echo b
b
$ echo c
c
$ fcn 3 1 | xsel -b
$ # Paste.
$  echo a &&  echo b &&  echo c
a
b
c
$ # Paste again if you feel like it.
$  echo a &&  echo b &&  echo c
a
b
c

Or for larger commands that might need some editing:

fcn 3 1 >cmds.sh
vi cmds.sh
bash cmds.sh
bash cmds.sh

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>