4

I'm not sure if this should be here or over on AskDifferent, but I'm using a bash shell (iTerm) on MacOS. I sometimes have commands that produce additional commands that need to be copy/paste to the terminal.

An example of this is logging into the aws ecr:

aws ecr get-login --no-include-email --region -eu-west-1

This produces a multiline login hash that you need to copy and paste to the shell in order to successfully authenticate. Is there a way I can this and paste it from the keyboard or some command?

I've seen several ways to copy all of the output from a command to clipboard, but that's not exactly what I'm asking for. Specifically, I typically only want the last line in the output.

If nothing exists, I'd be perfectly happy with just setting up some sort of alias in my .bashrc

The recommended dupe answer expects you to use screen - I don't want to use screen

1

1 Answer 1

2

Whatever you send to stdin of xclip will be stored in the clipboard (if you're running X). You can use tail to extract the last line of output:

for i in {1..10} ; do
    echo $i
done \
| tail -n1 | xclip

10 is now in the clipboard.

Oops, I haven't noticed the osx tag. On OS X, a similar command seems to be pbcopy.

Not the answer you're looking for? Browse other questions tagged .