Saturday 26 August 2017

macos - How to pass a terminal command as an argument to another command


I want to run this command:


ls -arth Test*log | tail -1

... and pass its output as an argument to:


open /Applications/Utilities/Console.app 

I would like to do this all in one line.



Answer



This is known as command substitution:


open /Applications/Utilities/Console.app "$(ls -arth Test*log | tail -1)"

If you're certain that the output of the command you're substituting won't contain spaces or newlines (or if you want to supply space/newline-separated output as multiple arguments), you can omit the quotes:


open /Applications/Utilities/Console.app $(ls -arth Test*log | tail -1)

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...