Pass a Command Line Argument to an Alias

Ever want to pass in a command line argument to an alias? You would think you could just do it with $1, but actually you have to create a function and then call that function. So, for instance if you want to pass a portion of a log file name, you could set your alias like this…

alias catlog='function _catIt() { cat /var/logs/$1.log; };_catIt'

then, when you want to see the XX00D log, you just call your alias like so…

catlog XX00D
Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Leave a Reply