Execute small bits from the clipboard in Terminal

Mar 25, '10 07:30:00AM

Contributed by: drewk

Perl and Bash programmers will recognize the backtick operator (`some_command`) as a way to cause the string enclosed in the backticks operator (some_command) to be executed as a command in the shell.

If you put some executable text on the OS X clipboard, this can also be directly executed with the backtick operator. For example, the shell command ls -l -G -a -F $HOME produces a colorized long listing of the user's home directory. Copy that command to the OS X clipboard.

In Terminal, type pbpaste, and you will get the text of the command. If you instead type `pbpaste`, the shell will execute the command and produce the directory listing.

[robg adds: This tidbit is most useful as part of a larger script, as seen in these examples. If you're in Terminal with some executable Unix command on the clipboard, you could run that command directly by pressing Command-V and Return.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090918131909109