Paste text stored on Clipboard to a variable using pbpaste I have some text stored on my clipboard. I want to store this text onto a shell script "variable".

So something like:

ls -altr &gt; pbcopy
tmp="something"
pbpaste &gt; $tmp    # this doesn't get the ls command output :(
echo $tmp         # should not print something
Try

ls | pbcopy
tmp=$(pbpaste)


And don't forget to remove the files called pbcopy and something you created with your first and second line.