I have a few Raspberry Pi at home, they’re used for specific purposes such as Kodi media player, Pi-hole server, and a backup DNS/DHCP server. Recently, I need to turn on the backup DNS/DHCP server, which is one of the Raspberry Pi devices running Arch Linux.

When I logged into to the server, I saw a message complaining that bash: append_path: command not found. It’s been so long since this little server, so I can’t remember what happened last time.

Welcome to Arch Linux ARM

     Website: http://archlinuxarm.org
       Forum: http://archlinuxarm.org/forum
         IRC: #archlinux-arm on irc.Freenode.net
Last login: Thu Dec  9 20:49:43 2021 from 192.168.1.114
-bash: append_path: command not found
-bash: append_path: command not found
-bash: append_path: command not found
-bash: append_path: command not found

I was curious and wanted to find out what causes this without going straight to Google. (It should be more fun if we can figure this out ourselves, right?)

The first place I checked is grep-ing the append keyword in ~/.bash_profile.

[kenno@alarmpi ~]$ grep append .bash_profile

Nothing. Alright, let’s check also the /etc/bash.bashrc.

[kenno@alarmpi ~]$ grep append /etc/bash.bashrc

Still nothing. How about /etc/profile?

[kenno@alarmpi ~]$ grep append /etc/profile --color
appendpath () {
appendpath '/usr/local/sbin'
appendpath '/usr/local/bin'
appendpath '/usr/bin'
unset -f appendpath

Well, I’ve got something this time. It looked like appendpath is a bash function. Though it didn’t exactly match the append_path, but that was at least a good indication that we could be on the right path (no pun intended).

Let’s refine our grep command to display the 15 lines after appendpath ().

[kenno@alarmpi ~]$ grep 'appendpath ()' /etc/profile -A 12
appendpath () {
    case ":$PATH:" in
        *:"$1":*)
            ;;
        *)
            PATH="${PATH:+$PATH:}$1"
    esac
}

appendpath '/usr/local/sbin'
appendpath '/usr/local/bin'
appendpath '/usr/bin'
unset -f appendpath

At this point, I spent about 15 minutes and it got nowhere. My excuse is since I don’t use Arch Linux and haven’t kept up with the changing Arch world, this is the perfect time to turn to Google for answer.

As predicted, someone had the same issue and also provided a solution too. You can read about it at [1]. Basically, there has been some changes to /etc/profile in Arch Linux and the changes was saved to a new file - /etc/profile.pacnew. It’s up to the Arch user to manually update /etc/profile.

A good tool for checking the difference between two (text) files is diff. Using diff on these files, it produced the following output:

[kenno@alarmpi ~]$ diff /etc/profile /etc/profile.pacnew
6,7c6,8
< # Append our default paths
< appendpath () {
---
> # Append "$1" to $PATH when not already in.
> # This function API is accessible to scripts in /etc/profile.d
> append_path () {
16,19c17,20
< appendpath '/usr/local/sbin'
< appendpath '/usr/local/bin'
< appendpath '/usr/bin'
< unset -f appendpath
---
> # Append our default paths
> append_path '/usr/local/sbin'
> append_path '/usr/local/bin'
> append_path '/usr/bin'
20a22
> # Force PATH to be environment
29a32,34
>
> # Unload our profile API functions
> unset -f append_path

It looked to me that the main difference between those files was just the name of the function changed from appendpath () to append_path (). We should be able to replace the content of /etc/profile with /etc/profile.pacnew’s. As a good practice, I first made a backup of the old file by renaming it to /etc/profile.old.

[kenno@alarmpi ~]$ sudo mv /etc/profile{,.old}
[kenno@alarmpi ~]$ sudo mv /etc/profile{.pacnew,}

Finally, we can confirm that the mentioned error message no longer existed.

[kenno@alarmpi ~]$ source /etc/profile
[kenno@alarmpi ~]$ source .bash_profile
[kenno@alarmpi ~]$

Well, that’s it. I hope you’ve learned something.

Reference:

[1] bash: append_path: command not found