xircon
January 21, 2022, 9:54pm
1
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)"
last2
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ 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
KDen
January 21, 2022, 10:12pm
2
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`'
dalto
January 21, 2022, 10:13pm
3
$(command)
indicates that the command should be run.
2 Likes
No it’s bash flavored expansion
$(command)
is exactly the same as POSIX
`command`
KDen
January 21, 2022, 10:23pm
5
It looks like he’s using zsh right? Does a bash expansion work in zsh?
1 Like
dalto
January 21, 2022, 10:28pm
6
That one does. zsh supports that syntax as well.
2 Likes
xircon
January 21, 2022, 10:51pm
8
Will look into it, @KDen back ticks equals $(), I tried it both ways just in case then forgot about it as it made no difference (age!!!)
KDen
January 21, 2022, 10:57pm
9
Is the file it’s failing out on a symlink? maybe that has something to do with it?
xircon
January 21, 2022, 11:00pm
10
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
KDen
January 21, 2022, 11:55pm
11
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
https://scriptingosx.com/2017/05/configuring-bash-with-aliases-and-functions/
So you need to create a function instead of an alias
function last2() {
bat $(find ~/.updates/ -print | tail -n2)
}
4 Likes
Gone when needed… - do it as a function…much more reliable and simpler!
manuel
January 22, 2022, 11:24am
13
Also this seems to work:
alias last2='find ~/.updates | tail -n2 | bat'
3 Likes
vlkon
January 22, 2022, 7:22pm
14
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,…
1 Like
vlkon
January 22, 2022, 7:32pm
16
Can you not see the beauty in that?
The OP question was how to make an alias. So here it is.
2 Likes
system
Closed
January 24, 2022, 7:33pm
17
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.