I couldn’t see a specific section for bash/scripting etc so not sure where to post the question.
I’m trying to make an alias called lastup that will tell me the last time the system was updated.
This is what I tried:
alias lastup='awk 'END{sub(/\[/,""); print $1}' /var/log/pacman.log'
And this is the error I’m getting when I open the terminal:
bash: /home/redacted/.bashrc: line 33: syntax error near unexpected token `('
bash: /home/redacted/.bashrc: line 33: `alias lastup='awk 'END{sub(/\[/,""); print $1}' /var/log/pacman.log''
I’m assuming the quotes within quotes is the issue but I don’t know enough bashfu to rephrase what I’m trying to achieve. Any bash wizards around to enlighten a noobie?
I’m also not completely sure what the line is doing, but if you need to add quotes inside of quotes you need to switch from single to double quotes, or you will just be ending the first quote instead of starting a new one.
As you have realized, inserting complicated (not a simple command with a couple of words/arguments) code in .bashrc is messing your system.
If you want to add an alias to something complicated, create a bash script, and use it as a simple command for an alias.
Depending on the exact use you will make of this, you can specify the type of operation (from the pacman log) that interests you. Just saying (in case you wondering about updates only )
I have endeavour os installed on some old machines and laptops trying out different setups and for learning, and if I get distracted and don’t update one for a while, I want a quick way to check the last time the system was updated so I know if to check for issues before doing an update etc.
As mentioned here that command only will produce the date of the last pacman transaction. It could be about updates but also installing one/some package/s or remove one/some package/s.
The OPs original solution was probably more efficient because it is a single awk call instead of running a program to get the last line and then piping it to awk.
They aren’t currently equivalent because of the substitution.
If you make them equivalent they are basically the same.
$ time lastup1
[2023-04-28T13:59:18-0500]
real 0m0.007s
user 0m0.007s
sys 0m0.000s
$ time lastup2
[2023-04-28T13:59:18-0500]
real 0m0.006s
user 0m0.007s
sys 0m0.000s