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.
 

raydon

Well-Known Member
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.
 

af123

Administrator
Staff member
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.
 

raydon

Well-Known Member
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:
OP
prpr

prpr

Well-Known Member
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:

af123

Administrator
Staff member
The only problem is that I don't think your aliases will carry across to the new exec-d shell...
 
OP
prpr

prpr

Well-Known Member
Ah, you're right they don't. What's reading the files in .../profile/ then?
 

raydon

Well-Known Member
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:

af123

Administrator
Staff member
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.
 

raydon

Well-Known Member
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).
 

af123

Administrator
Staff member
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.
 

raydon

Well-Known Member
Had to change if [ "$0" = '-sh' ]; then to if [ "$0" = '/bin/sh' ]; then to get it to work.
Great stuff ! :thumbsup:
 

af123

Administrator
Staff member
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
 
OP
prpr

prpr

Well-Known Member
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?
 

af123

Administrator
Staff member
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]
 
Top