Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/docs/ksh/scripts/env.txt
1798 views
1
#! /usr/bin/ksh
2
# shell version of env command
3
case $(getopts '[-]' opt '--???man' 2>&1) in
4
version=[0-9]*)
5
usage=$'[-?@(#)env (AT&T Labs Research) 1999-05-20\n]
6
[-author?David Korn <[email protected]>]
7
[-license?http://www.research.att.com/sw/tools/reuse]
8
[+NAME?env - set environment for command invocation]
9
[+DESCRIPTION?\benv\b modifies the current environment according
10
to the \aname\a\b=\b\avalue\a arguments, and then
11
invokes \acommand\a with the modified environment.]
12
[+?If \acommand\a is not specified, the resulting environment
13
is written to standard output quoted as required for
14
reading by the \bsh\b.]
15
[i:ignore-environment?Invoke \acommand\a with the exact environment
16
specified by the \aname\a\b=\b\avalue\a arguments; inherited
17
environment variables are ignored. As an obsolete feature,
18
\b-\b by itself can be specified instead of \b-i\b.]
19
[u:unset]:[name?Unset the environment variable \aname\a if it was
20
in the environment. This option can be repeated to unset
21
additional variables.]
22
23
[name=value]... [command ...]
24
25
[+EXIT STATUS?If \acommand\a is invoked, the exit status of \benv\b
26
will be that of \acommand\a. Otherwise, it will be one of
27
the following:]{
28
[+0?\benv\b completed successfully.]
29
[+126?\acommand\a was found but could not be invoked.]
30
[+127?\acommand\a could not be found.]
31
}
32
[+SEE ALSO?\bsh\b(1), \bexport\b(1)]
33
'
34
;;
35
*)
36
usage='iu:[name] [name=value]... [command ...]'
37
;;
38
esac
39
clear=
40
while getopts "$usage" var
41
do case $var in
42
i) clear=1;;
43
u) command unset $OPTARG 2> /dev/null;;
44
esac
45
done
46
#[[ $var == "" ]] || exit 1
47
shift $((OPTIND-1))
48
if [[ $1 == - ]] # obsolete form
49
then clear=1
50
shift
51
fi
52
if [[ $clear == 1 ]]
53
then typeset +x $(typeset +x)
54
fi
55
while true
56
do case $1 in
57
*=*) export "$1";;
58
*) break;;
59
esac
60
shift
61
done
62
if (( $# >0 ))
63
then exec "$@"
64
else export
65
exit 0
66
fi
67
68