[net.unix-wizards] help on $cdpath

warner (12/22/82)

	I am trying to access the login shell's variable
$cdpath ... without success. The relevant code fragment is below.
I'v tried about every combination of ("csh -t echo $cdpath) etc.
with all the combinations of ' " and ` that I can think of. No luck.
I can call my program with $cdpath as an argument but I don't want
to. Any suggestions besides giving up programming.
Ken Warner  ...ucb!sdcsvax!sdcsla:warner or net.followup 
--------------------------------------------------------------------
	FILE *pwd, *popen();
	char cdpath[128],curdir[128];
	if ((pwd = popen("echo $cdpath","r")) == NULL)
	{
		printf("can't open pwd\n");
		exit(1);
	}
	fgets(cdpath,128,pwd);
	pclose(pwd);
	cdpath[strlen(cdpath) - 1] = '\0';
	printf("cdpath = %s\n",cdpath);
	exit(1);

mjb (12/22/82)

You are trying to access a variable *local* to the login shell, which is not
recommended. If you insist on doing it, make sure the cdpath setting is done
in the .cshrc, then replace the "echo..." in the popen() call with:
"csh -c 'echo $cdpath'". Note that this is *slow*. You might consider setting
an environment variable--by convention do:
setenv CDPATH "$cdpath"
then the following would work:

	char *cdpath, *getenv();
	if ((cdpath = getenv("CDPATH")) == NULL) {
		printf("Undefined\n");
		exit(1);
	}
	printf("cdpath = %s\n",cdpath);
	exit(0);

\mike braca  {vax135,decvax}!brunix!mjb
[Note: I am submitting this to the net because of the trouble we have been
 having getting mail through 'harpo']