i am in the process of creating a simple shell written in c and used in unix. i have covered all my basis including pipes, redirection. etc. but i am having difficulty with environmental variables and variable substitution. the assignment requests:
builtin functions:
set [ <name> <value> ]
unset <name>
setenv [ <name> <value> ]
unsetenv <name>
getshv(<name>) that acts like getenv(3c)
putshv(<name>,<value>) that acts like putenv(3c)
and use an external shvar that acts like environ
char *shvar[];
with up to 1024 shell variables, as determined by:
#define NSHVAR 1024
variable sub:
Only ${<name>} or ${<digit>} required
You can, if you wish, do $PATH or $1 also.
Substitution can be anywhere in a command line including a whole line:
set mycmd “ls –l *.c”
è ${mycmd}
$(digit) positional parameters like $0 $1 $2 ...
These are the arguments passed to your shell program from the argv[] array.
mysh -f a b c
-> echo ${0}
mysh
-> echo ${1}
-f
-> echo ${2}
a
-> echo ${#}
5
any help that anyone could give me in coding this would be appreciated. thanks
builtin functions:
set [ <name> <value> ]
unset <name>
setenv [ <name> <value> ]
unsetenv <name>
getshv(<name>) that acts like getenv(3c)
putshv(<name>,<value>) that acts like putenv(3c)
and use an external shvar that acts like environ
char *shvar[];
with up to 1024 shell variables, as determined by:
#define NSHVAR 1024
variable sub:
Only ${<name>} or ${<digit>} required
You can, if you wish, do $PATH or $1 also.
Substitution can be anywhere in a command line including a whole line:
set mycmd “ls –l *.c”
è ${mycmd}
$(digit) positional parameters like $0 $1 $2 ...
These are the arguments passed to your shell program from the argv[] array.
mysh -f a b c
-> echo ${0}
mysh
-> echo ${1}
-f
-> echo ${2}
a
-> echo ${#}
5
any help that anyone could give me in coding this would be appreciated. thanks