I have a board with the default shell being sh. At the end of "/etc/profile" there is:
exec /bin/ashThis changes the shell to ash.
What should I do if want to execute a file where I defined some aliases in ash?
I tried using:
exec /bin/ash -f /root/aliases.shBut when I login to the board using ssh it exits saying connection closed.
Any other way?
1 Answer
When you run exec /bin/ash -f /root/aliases.sh ash runs non-interactively, and it exits as soon as "/root/aliases.sh" has been executed; that's why the SSH session ends.
So the solution is to run the shell interactively; from man 1 ash:
If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file.
So just set ENV in "~/.profile":
export ENV=/root/aliases.shand run the shell interactively:
exec /bin/ashHowever notice that:
- Running
exec /bin/ashat the end of "~/.profile" will replace any shell sourcing "~/.profile" (i.e. any login shell) with anashinstance; - This makes no sense. The correct way to get
ashas a login shell for an user is to change the login shell for the user, which can be done usingchsh.
So I really suggest you to remove exec /bin/ash from "~/.profile" and to change the login shell for the user using chsh instead.