Will
Will

Reputation: 2410

Name a function as an environment command

I wonder if there is a way to create a script as following :

#!/bin/ksh
export() {
echo "We're in the local function"
}
export

The main issue is that exportis an environment command for setting value of a variable or an environment variable, so when this script is run it will just prompt something like :

LOGIN=autosys
LOGNAME=autosys
MAIL=/usr/spool/mail/autosys
PWD=/home/autosys/wlp
SHELL=/usr/bin/ksh
TZ=Europe/Paris
HOME=/home/autosys
...

Obviously I could just name my function with a different name but as I am curious (and because this function should really be named export, logic purpose), I wonder if there is a way letting the script know I want to run the local export() function and not the environment command.

For example something like

    export(){...}
    call function(export) 

Upvotes: 2

Views: 36

Answers (1)

Gaétan RYCKEBOER
Gaétan RYCKEBOER

Reputation: 304

Yes, export is a reserved word in shell. You will have to choose a different name.

Furthermore, you will have to source your shell script to apply any export to current shell instead of his son, forked.

If you really want to invoke something named “export”, use a shell file named “export”, for instance in /usr/local/bin:

/usr/local/bin/export bimbo lola juliet

Upvotes: 1

Related Questions