What am I doing wrong?

Backstory, I run emacs native comp branch from ArchlinuxCN and it updates a lot, sometimes twice a day or more, which leads to the elncache being rebuilt after every update. So I thought I would only update once a week and wrote this, but it is failing:

DAY=$(date +"%u")
echo ">>>>>>>>>"$DAY
if [ "$DAY" == "2" ]; then #fails here ***********************
    echo "Equal"
    sudo sed -i 's/#IgnorePkg = emacs-native-comp-git/IgnorePkg = emacs-native-comp-git/' /etc/pacman.conf
    echo "Not Equal"
    sudo sed -i 's/IgnorePkg = emacs-native-comp-git/#IgnorePkg = emacs-native-comp-git/' /etc/pacman.conf

This is just the bit that goes wrong, I know the sed commands work OK, so it is my logic???

It works fine here(without the sed lines). Are you sure you are running it in bash?

What happens when you run it?

1 Like

An alternative in case statement

case "$(date +%a)" in
     sudo sed -i 's/#IgnorePkg = emacs-native-comp-git/IgnorePkg = emacs-native-comp-git/g' /etc/pacman.conf
     sudo sed -i 's/IgnorePkg = emacs-native-comp-git/#IgnorePkg = emacs-native-comp-git/g' /etc/pacman.conf

Can you check in /etc/pacman.conf if the spacing matches like in this? #IgnorePkg = emacs-native-comp-git (note that there is only 1 space after IgnorePkg then another space, in the default pacman.conf there are a 2/3 spaces after #IgnorePkg so sed will not write/change it because of that)

1 Like


║ Updating Mirrors ║
║ Finding fastest Arch mirror....... ║
║ Mirrors have already been updated today! ║
:: Synchronizing package databases...
 kde-unstable is up to date
 gnome-unstable is up to date
 core is up to date
 extra is up to date
 community                                                           5.6 MiB  1741 KiB/s 00:03 [-------------------------------------------------------] 100%
 multilib is up to date
 endeavouros is up to date
 archlinuxcn is up to date
 chaotic-aur                                                      1373.9 KiB   678 KiB/s 00:02 [-------------------------------------------------------] 100%
 liquorix is up to date
 jk-aur is up to date
 herecura is up to date
/home/xircon/scripts/syu.sh:56: = not found

I am using zsh because of the very handy fork and disown - &!

Got it! My internet foo is weak today:

[[ == ]] or [ = ]

Double equals needs two “[”

1 Like

Well that was three hours of my life I will not get back :rofl:

1 Like

S* Happens xd :rofl: :rofl:

1 Like

I like the case approach, would never have thought of that.

It shouldn’t in bash. That is why I was asking about your shell.

In general, there are a lot of differences between zsh and bash. They are have different extensions to POSIX. If you want something to work in either shell, just make is POSIX compliant.

Alternatively, even if you use zsh, that script could be executed in bash.

I try to do all my scripting in bash even though I use zsh.

1 Like

True, 2 minute conversion :smiley: