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