Bash script convert for mksh?
#1
Bash script convert for mksh?
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
stormy
Atari expert!

Trade Count: (1)
Posts: 180
Threads: 34
Joined: May 2019
Location: UK
Find Reply
01-04-2021, 08:59 PM
#2
RE: Bash script convert for mksh?
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/tru...ksh.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.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
(This post was last modified: 01-04-2021, 09:52 PM by Raion.)
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,239
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
01-04-2021, 09:51 PM
#3
RE: Bash script convert for mksh?
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.

Personaliris O2 Indigo2 R10000/IMPACT Indigo2 R10000/IMPACT Indigo2 Indy   (past: 4D70GT)
robespierre
refector peritus

Trade Count: (0)
Posts: 640
Threads: 3
Joined: Nov 2020
Location: Massholium
Find Reply
01-06-2021, 02:27 AM


Forum Jump:


Users browsing this thread: 1 Guest(s)