What's new

SOLVED: Configure/ customise Merlin shell?

  • 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!

gspannu

Senior Member
What is the underlying shell for Merlin? Is it bash or zsh or something similar?

I need to do some initialisation as one could do in .bash_rc or .zshrc or .profile?
Any guides or helpful links?

Thanks.
 
More specifically, it's BusyBox's ash. Documentation is pretty slim, especially considering a lot of the features can be toggled during compile time, your best bet would be to look at POSIX compatibility. There's a general ash manual here, and the compile options are here.

So it'd be the base ash, minus:
  • Job control: fg [job], bg [job], jobs, wait [job] (although waiting for a child processes still works)
  • Command built-in: command command arg...
  • Random: $RANDOM
Plus bash-compatible extensions:
  • Redirecting stdout and stderr: &>file
  • Dollar quoting: $'...'
  • Parameter replacement: ${var/pattern/replacement}, ${var//pattern/replacement}
  • Parameter substrings: ${var:start:length}
  • Test expressions: [[...]]
  • Sourcing files with a '.'
  • Pipefails
  • HOSTNAME/SHLVL/BASH_XTRACEFD variables
  • Custom read delimiters: read -d
  • Waiting for any job: wait -n

For profiles, you can see the default settings in /etc/profile:
Code:
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/home/$USER:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin"
export PS1='\u@\h:\w\$ '

alias l='ls -lFA'
alias ll='ls -lF'

ldd() {
    LD_TRACE_LOADED_OBJECTS=1 $*;
}

[ -n "${TMOUT+x}" ] || export TMOUT="$(nvram get shell_timeout 2>/dev/null)"

[ -f /opt/etc/profile ] && . /opt/etc/profile
[ -f /jffs/configs/profile.add ] && . /jffs/configs/profile.add
 
It's ash
You can add stuff with /jffs/configs/profile.add

More specifically, it's BusyBox's ash. Documentation is pretty slim, especially considering a lot of the features can be toggled during compile time, your best bet would be to look at POSIX compatibility. There's a general ash manual here, and the compile options are here.

So it'd be the base ash, minus:
  • Job control: fg [job], bg [job], jobs, wait [job] (although waiting for a child processes still works)
  • Command built-in: command command arg...
  • Random: $RANDOM
Plus bash-compatible extensions:
  • Redirecting stdout and stderr: &>file
  • Dollar quoting: $'...'
  • Parameter replacement: ${var/pattern/replacement}, ${var//pattern/replacement}
  • Parameter substrings: ${var:start:length}
  • Test expressions: [[...]]
  • Sourcing files with a '.'
  • Pipefails
  • HOSTNAME/SHLVL/BASH_XTRACEFD variables
  • Custom read delimiters: read -d
  • Waiting for any job: wait -n

For profiles, you can see the default settings in /etc/profile:
Code:
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/home/$USER:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin"
export PS1='\u@\h:\w\$ '

alias l='ls -lFA'
alias ll='ls -lF'

ldd() {
    LD_TRACE_LOADED_OBJECTS=1 $*;
}

[ -n "${TMOUT+x}" ] || export TMOUT="$(nvram get shell_timeout 2>/dev/null)"

[ -f /opt/etc/profile ] && . /opt/etc/profile
[ -f /jffs/configs/profile.add ] && . /jffs/configs/profile.add

Thank you @ColinTaylor @Dabombber

Can you please give me small example of
- how one would add a path statement or a prompt customisation or an alias via profile.add?
- how to test/ load the profile.add without restarting?

I have looked here, but could not find much.
https://github.com/RMerl/asuswrt-merlin.ng/wiki/Custom-config-files

I believe an alternative is to directly edit the etc/profile; but I don't think that is a good idea.
 
Any changes made directly to /etc/profile will be lost after a reboot. That's what profile.add is for. Any lines you put into that file will be appended to /etc/profile.
 
Can you please give me small example of
- how one would add a path statement or a prompt customisation or an alias via profile.add?
- how to test/ load the profile.add without restarting?

You just need to set the PATH/PS1 variables, which can be done without reconnecting. To test profile.add, you can source it ("source /jffs/configs/profile.add" or ". /jffs/configs/profile.add"), although that may not be ideal if you've added anything which should only run once. For example, the config I use for profile.add is here.

It is possible to break SSH with a dodgy profile.add, so if you're worried about that you could test first using /opt/etc/profile. That way you could always remove the drive if anything goes wrong.
 

Attachments

  • console.png
    console.png
    113.7 KB · Views: 368
@Dabombber Ty for that profile.add script. One question, is there a way to also remove the "username@domain" at the beginning of each prompt?

that part where I crossed out in this screenshot (plus the use name to the left), so only the paths show.

1671545613154.png
 
is there a way to also remove the "username@domain" at the beginning of each prompt?
Code:
glen@zenmaster:/tmp/home/root# echo _${PS1}_
_\u@\h:\w\$ _
glen@zenmaster:/tmp/home/root# PS1='\h:\$ '
zenmaster:#

I threw in the underscores to indicate there's a blank space at the end of the prompt.

Don't know how many of the escape codes are supported on the router, but here's a list from "man bash" on a gnu-linux box:
Code:
              \a     an ASCII bell character (07)
              \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
              \D{format}
                     the format is passed to strftime(3) and the result is inserted into  the
                     prompt  string; an empty format results in a locale-specific time repre‐
                     sentation.  The braces are required
              \e     an ASCII escape character (033)
              \h     the hostname up to the first `.'
              \H     the hostname
              \j     the number of jobs currently managed by the shell
              \l     the basename of the shell's terminal device name
              \n     newline
              \r     carriage return
              \s     the name of the shell, the basename of $0 (the portion following the fi‐
                     nal slash)
              \t     the current time in 24-hour HH:MM:SS format
              \T     the current time in 12-hour HH:MM:SS format
              \@     the current time in 12-hour am/pm format
              \A     the current time in 24-hour HH:MM format
              \u     the username of the current user
              \v     the version of bash (e.g., 2.00)
              \V     the release of bash, version + patch level (e.g., 2.00.0)
              \w     the current working directory, with $HOME abbreviated with a tilde (uses
                     the value of the PROMPT_DIRTRIM variable)
              \W     the basename of the current working directory,  with  $HOME  abbreviated
                     with a tilde
              \!     the history number of this command
              \#     the command number of this command
              \$     if the effective UID is 0, a #, otherwise a $
              \nnn   the character corresponding to the octal number nnn
              \\     a backslash
              \[     begin  a sequence of non-printing characters, which could be used to em‐
                     bed a terminal control sequence into the prompt
              \]     end a sequence of non-printing characters
 
Last edited:
Code:
glen@zenmaster:/tmp/home/root# echo _${PS1}_
_\u@\h:\w\$ _
glen@zenmaster:/tmp/home/root# PS1='\h:\$ '
zenmaster:#

Thanks, that removed everything but the domain. I'm trying to make my above screenshot look like this (shows only the paths; excluding the user and domain) :):

1671569104738.png
 
@glens Aha, thanks!

Just needed to delete some stuff. Your examples clued me in. :)

Bash:
  # Before: With User + Host
  PS1="\[\e[37;41m\]\u\[\e[31;45m\]$ARROW\[\e[37m\]\h\[\e[m\e[35m\]$ARROW\[\e[m\e[7;34m\]$ARROW\[\e[27;37;44m\]\w\[\e[m\e[34m\]$ARROW\[\e[m\] "

  # After, removing User + Host
  PS1="\[\e[27;37;44m\]\w\[\e[m\e[34m\]$ARROW\[\e[m\] "
 

Latest threads

Sign Up For SNBForums Daily Digest

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