You can simulate this bit of fun with the env
command
env Clear Workspace=true bash
That will give you a shell with the environment variable set.
A hacky way, which should work up to bash 4.0, to get the environment variable value back out is:
declare -p Clear Workspace | sed -e "s/^declare -x Clear Workspace="//;s/"$//"
Bash versions starting with 4.0 will instead return an error and are unable to extract such environment variables in that way.
Other than that you'd need to use either a native code program or a scripting language to pull it out, e.g.
ruby -e "puts ENV['Clear Workspace']"
Which is much less hacky... also if you don't have ruby
perl -e 'print "$ENV{"Clear Workspace"}
";'
also
python -c 'import os; print os.environ["Clear Workspace"]'
And here is a native code version:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv, char **envp)
{
char **env;
char *target;
int len;
if (argc != 2)
{
printf("Syntax: %s name
", argv[0]);
return 2;
}
len = strlen(argv[1]);
target = calloc(len+2,sizeof(char));
strncpy(target,argv[1],len+2);
target[len++] = '=';
target[len] = '0';
for (env = envp; *env != 0; env++)
{
char *thisEnv = *env;
if (strncmp(thisEnv,target,len)==0)
{
printf("%s
",thisEnv+len);
return 0;
}
}
return 1;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…