• The forum software that supports hummy.tv has been upgraded to XenForo 2.3!

    Please bear with us as we continue to tweak things, and feel free to post any questions, issues or suggestions in the upgrade thread.

Shell queries

prpr

Well-Known Member
Is there an easy way to make something like this persistent when telnetted in to the Humax?
Code:
humax# alias scp="scp -i /mod/.ssh/db_rsa"
humax# alias
scp='scp -i /mod/.ssh/db_rsa'
This only lasts for the instance of "sh" you are running.
 
You're welcome. Another question on shell which someone may be able to answer. Why doesn't export PS1="\h\w\# " change the command prompt ? The string is taken literally, instead of interpreting the escaped characters as hostname and current working directory respectively.
 
ASH_EXPAND_PRMT is not set in the build for the root filesystem busybox.
It is for the one in /mod/bin so you could switch, or even run it from a profile script

Code:
HDR-Fox T2 1.03.12/3.00

humax/mnt/hd2/mod# cat /mod/etc/profile/zz

if [ -x /mod/bin/busybox/sh ]; then
  export PS1="\h\w\# "
  exec /mod/bin/busybox/sh
fi

humax/mnt/hd2/mod#

The version of ash on disk has a lot more features enabled as size isn't such an issue.
 
Thanks for that af123, I'll set that up. I like the prompt to show which folder I'm in.
EDIT: Done, works a treat ! :thumbsup:
 
Last edited:
Excellent stuff. Been wanting to know how to do this for ages. I've coloured mine like all my others now. :)
Code:
if [ -x /mod/bin/busybox/sh ]; then
  export PS1="\[\033[01;32m\]\h\[\033[01;34m\] \w \# \[\033[00m\]"
  exec /mod/bin/busybox/sh
fi
I renamed the file to "sh" from "alias" and stuck everything in there.
 
Last edited:
The only problem is that I don't think your aliases will carry across to the new exec-d shell...
 
Ah, you're right they don't. What's reading the files in .../profile/ then?
 
Ah, you're right they don't. What's reading the files in .../profile/ then?
/etc/profile, which is in the read-only file system.
Maybe the part that runs the stuff in /mod/etc/profile could be defined as a function
which would be then executed in the same shell, not a subshell.

do_profile()
{
for f in /mod/etc/profile/*; do
[ -f "$f" ] || continue
. "$f"
done
}

do_profile

Not really sure about my facts here though, and it would need a new firmware build to test the theory.
 
Last edited:
Use this instead:

Code:
# Stuff for both shells
alias ls='ls -CFh'

if [ "$0" = '-sh' ]; then
    # If in the default login shell and the better one is available, then...
    [ -x /mod/bin/busybox/sh ] && exec /mod/bin/busybox/sh -l
else
    # Things to run in the better shell only.
    export PS1="\[\033[01;32m\]\h\[\033[01;34m\] \w \# \[\033[00m\]"
fi

The -l argument to sh causes it to act as a login shell and therefore process /etc/profile.
The $0 test is necessary to stop the loop. In the /else/ part you're in the new shell so can set anything you want there, or keep the aliases in separate files so they apply to both shells.
 
An elegant solution. Was I barking up the wrong tree completely with my earlier suggestion? I did recognise I was in uncharted territory (for me anyway).
 
I think so - the scripts are already run in the main shell as they are sourced but the exec call replaces the first shell with the second which does not have things like the aliases present.
 
Had to change if [ "$0" = '-sh' ]; then to if [ "$0" = '/bin/sh' ]; then to get it to work.
Great stuff ! :thumbsup:
 
Had to change if [ "$0" = '-sh' ]; then to if [ "$0" = '/bin/sh' ]; then to get it to work.
Great stuff ! :thumbsup:
Ah, I'm connecting via ssh, that could be the difference so the full solution is:

Code:
# Stuff for both shells
alias ls='ls -CFh'

if [ "$0" = '-sh' -o "$0" = '/bin/sh' ]; then
     # If in the default login shell and the better one is available, then...
     [ -x /mod/bin/busybox/sh ] && exec /mod/bin/busybox/sh -l
else
     # Things to run in the better shell only.
     export PS1="\[\033[01;32m\]\h\[\033[01;34m\] \w \# \[\033[00m\]"
fi
 
Ah, I'm connecting via ssh, that could be the difference so the full solution is:
It is the difference. SSH for the former and Telnet for the latter.
Code:
if [ "$0" = '-sh' -o "$0" = '/bin/sh' ]; then
This doesn't work for me using Telnet. An "echo $0" produced "-/bin/sh" rather than "/bin/sh"
I had to change the above line to include the '-' and then it worked. Did someone make a typo. here?

What is the meaning of the '-' anyway?
 
The leading - means it's a login shell. To cause login processing to occur, a shell can either be invoked with a -l argument or with a leading - in argv[0]
 
Back
Top