Bash script convert for mksh? -
stormy - 01-04-2021
Hi everyone,
I have this script which runs inside /etc/profile.d/which2.sh
Code:
# Initialization script for bash and sh
which() {
(alias && declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-dot --show-tilde $@
}
export -f which
It executes whenever the shell is loaded. The default shell is bash, but I'm using mksh for speed reasons. When opening the mksh shell I get an error: 'export: -f: unknown option'
Ideally I want to keep the functionality of this script, but make it mksh compatible while still working with bash. If it is too difficult to make compatible with mksh perhaps I could put it in bashrc instead I wonder.
Is this possible? Thanks
RE: Bash script convert for mksh? -
Raion - 01-04-2021
So ksh and bash do not generally have the same export syntax.
Mksh even moreso, so you'll need to familiarize yourself with mksh:
https://manpages.ubuntu.com/manpages/trusty/man1/mksh.1.html
It should be noted on IRIX the default interactive shell is usually csh or tcsh, and depending on what functionality you use in GNU Bash or KSH88/MKSH, you may find it faster to just use tcsh.
For instance, the main things that I used to use for Bash when I was a Linux user have similar conventions:
Directional history (i.e. using up/down to cycle through old commands, same as bash)
Tab completion of commands and paths
Colored prompts (have to use older syntax for it)
Execute prior command argument (ESC+. In Bash, but append !$ to tcsh)
But again, use what you're comfortable with, and I can appreciate the need for performance. bash is slower than a dog.
RE: Bash script convert for mksh? -
robespierre - 01-06-2021
The -f option to export is what caused the whole Shellshock fiasco (if you remember). It's a misfeature.
The functionality you are looking for is available in ksh shells in the builtin "whence -a". It is aliased by default to "type". It is also faster, since it doesn't invoke an external command.