Environment variables: Difference between revisions
Content deleted Content added
mNo edit summary |
Add LIL |
||
Line 565: | Line 565: | ||
end select |
end select |
||
end function</lang> |
end function</lang> |
||
=={{header|LIL}}== |
|||
LIL does not ship with a command to retrieve process environment variables. The '''system''' command could be used, but here is an extension in C for the lil shell. |
|||
<lang c> |
|||
static LILCALLBACK lil_value_t fnc_env(lil_t lil, size_t argc, lil_value_t* argv) |
|||
{ |
|||
if (!argc) return NULL; |
|||
return lil_alloc_string(getenv(lil_to_string(argv[0]))); |
|||
}</lang> |
|||
Then inside the main functions for repl and nonint (Interactive, Noninteractive): |
|||
<lang c>lil_register(lil, "env", fnc_env);</lang> |
|||
Now lil can get at the environment. That could fairly easily be extended further to return the entire environment array if no arguments are passed to '''env''', this just returns an empty result for that case. Defaults values could also be supported if the named environment variable is empty. Etcetera. Setting variables would be similar, a few lines of lil C to wrap a call to libc setenv in a new command, and registering the command. |
|||
{{out}} |
|||
<pre>prompt$ make |
|||
cc -c -g3 -std=c99 -pedantic -Wall -Wextra -Wno-format -Wno-long-long -Wno-unused-parameter main.c -o main.o |
|||
cc -g -L. -o lil main.o -llil -lm |
|||
prompt$ lil |
|||
Little Interpreted Language Interactive Shell |
|||
# env TERM |
|||
xterm-256color</pre> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |