How do I make this an alias?

Works from the command prompt:

bat `find ~/.updates/  -print | tail -n2`

Fails from an alias. Should cat the last two files in the directory:

alias last2="bat $(find ~/.updates/  -print | tail -n2)"
       │ File: /home/xircon/.updates/2022-01-21T08:12
   1   │ deadbeef-git r10768.a3f57752a-1 -> r10769.9f221c9a3-1
   2   │ npm 8.3.1-1 -> 8.3.2-1
   3   │ qt5-quickcontrols2 5.15.2+kde+r9-1 -> 5.15.2+kde+r10-1
   4   │ rust 1:1.58.0-1 -> 1:1.58.1-1
zsh: permission denied: /home/xircon/.updates/2022-01-21T18:54

Bat is a fancy cat alternative :smiley:

I’m not an expert but doesn’t the $ symbol indicate a variable? Why did you change it from the working command?
Shouldn’t it just be this?

alias last2='bat `find ~/.updates/  -print | tail -n2`'

$(command) indicates that the command should be run.


No it’s bash flavored expansion


is exactly the same as POSIX


It looks like he’s using zsh right? Does a bash expansion work in zsh?

1 Like

That one does. zsh supports that syntax as well.


Will look into it, @KDen back ticks equals $(), I tried it both ways just in case :smiley: then forgot about it as it made no difference (age!!!)

Is the file it’s failing out on a symlink? maybe that has something to do with it?

Nope. Everytime I update, I output checkupdates+aur to a file in the ~/.updates/ directory. I can script my way out of it but just couldn’t understand why the one-liner would not work as an alias.

1 Like

I installed bat and gave it a try. Here’s some info that might help.
I got the same result. Worked directly from the command line but permission denied as an alias.

However, I tried it in Fish Shell and it works. Aliases in Fish Shell are actually functions. So that got me looking.
From my understanding zsh and bash alias are a bit more limiting than other shells

So you need to create a function instead of an alias

function last2() {
	bat $(find ~/.updates/  -print | tail -n2)

Gone when needed… - do it as a function…much more reliable and simpler!

Also this seems to work:

alias last2='find ~/.updates | tail -n2 | bat'

When you have function it is easy to turn it into an alias.

alias mcd='function _mcd(){ mkdir -p "$1"; cd "$1"; };_mcd '    # create a directory and cd into it
alias last2='function _last2(){ bat $(find ~/.updates/ -print | tail -n2); }; _last2 '

Is that more useful than just calling a function? Well,… :smiley:

1 Like

But… why?


Can you not see the beauty in that? :laughing:
The OP question was how to make an alias. So here it is.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.