What's new

Entware How to change path?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Turgut Kalfaoglu

Regular Contributor
Recently I noticed that when I try
# ps ax

The system's own /bin/ps runs and rejects the ax options. I was hoping for /opt/bin/ps to run instead.
I was wondering how to put /opt/bin in front of /bin in path.
or is that something that could cause problems?

Thanks!
-t
 
It's pretty much as simple as you've said, put /opt/bin first in the PATH variable.

Bash:
PATH="/opt/bin:$PATH"

You can try it directly to see if it works, or if you want it that way every time, put it in your /jffs/configs/profile.add. If you're worried about duplicate PATH entries, you can clean it up a bit afterwards.

Bash:
removepath() {
    local MYPATH=":$PATH:"
    local ARG
    for ARG in "$@"; do
        MYPATH="${MYPATH/:"$ARG":/:}"
    done
    MYPATH="${MYPATH%:}"
    MYPATH="${MYPATH#:}"
    PATH="$MYPATH"
}

cleanpath() {
    PATH="$(printf '%s' "$PATH" | awk -vRS=: -vORS= '!a[$0]++ {if (NR>1) printf(":"); printf("%s", $0) }' )"
}

cleanpath
removepath '/home/admin' '/mmc/sbin' '/mmc/bin' '/mmc/usr/sbin' '/mmc/usr/bin' '/opt/usr/sbin' '/opt/usr/bin'

The PATH variable will only be for your SSH session rather than everywhere on the router, so it shouldn't break anything too horribly (I thought it was the default anyway? You may need to check your entware install). If you do have any issues you could always use an alias instead.

Bash:
alias ps="/opt/bin/ps"
 
many thanks for all your replies!
I put the PATH="/opt/bin:$PATH" into /jffs/configs/profile.add
 
If you only want to override precedence of that one "ps" command (and not everything in /opt/bin), you could set an alias in profile.add
alias ps=/opt/bin/ps
 
Don't change the path order, as it might cause malfunctions as the router could end up using Entware versions of shell commands instead of the built-in ones for its own internal functions.

Consider creating an alias instead.
 
Don't change the path order, as it might cause malfunctions as the router could end up using Entware versions of shell commands instead of the built-in ones for its own internal functions.

Consider creating an alias instead.

Entware puts itself first on the PATH list in /opt/etc/profile, which is included from /etc/profile ([ -f /opt/etc/profile ] && . /opt/etc/profile). I suspect there's a problem with Turgut's installation.
 
Entware puts itself first on the PATH list in /opt/etc/profile, which is included from /etc/profile ([ -f /opt/etc/profile ] && . /opt/etc/profile). I suspect there's a problem with Turgut's installation.

It appends itself at the end, not at the beginning (I did have an argument about that with the Entware maintainers a few years ago). That way it won`t override the router`s own, sometimes customized, busybox applets.
 
It appends itself at the end, not at the beginning (I did have an argument about that with the Entware maintainers a few years ago). That way it won`t override the router`s own, sometimes customized, busybox applets.
Then I think he's ignored your advice. My version of /opt/etc/profile (dated 6th June) adds it to the front of the path. (The firmware already has /opt entries at the end of the default path)
 
Then I think he's ignored your advice. My version of /opt/etc/profile (dated 6th June) adds it to the front of the path. (The firmware already has /opt entries at the end of the default path)

Or maybe we ended up with a compromise, I can't remember because it was years ago. At the time I remember my biggest problem was that he was also making busybox installed by default. The two together were firmware-breaking as any Entware setup would override the built-in applets. He backed down on including busybox by default, maybe my memory's wrong regarding the path order.
 
Or maybe we ended up with a compromise, I can't remember because it was years ago. At the time I remember my biggest problem was that he was also making busybox installed by default. The two together were firmware-breaking as any Entware setup would override the built-in applets. He backed down on including busybox by default, maybe my memory's wrong regarding the path order.
:D His memory is similar to yours. :D In a recent bug in sysstat that I reported he said "AFAIK $PATH on asuswrt-merlin contains /usr/bin before /opt/bin for some reason, to preserve some firmware specific behavior." ... which is actually true because we were discussing a non-tty issue (i.e. cron).
 
Similar threads
Thread starter Title Forum Replies Date
J scMerlin scMerlin 2.5.4 change log? Asuswrt-Merlin AddOns 1
P Change cronjob times Asuswrt-Merlin AddOns 4

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top