The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
querry ..including external shell script mobydick Shell Programming and Scripting 3 05-22-2008 09:31 AM
Repeating variables in the code mahalakshmi Shell Programming and Scripting 1 02-08-2007 07:33 AM
Reading a path (including ref to shell variable) from file lojzev Shell Programming and Scripting 1 09-11-2006 12:05 AM
how to convert from korn shell to normal shell with this code? forevercalz Shell Programming and Scripting 21 11-23-2005 02:18 AM
server based Including additional code > Lycos way valentijnb UNIX for Dummies Questions & Answers 1 07-05-2003 07:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-26-2007
bdsffl bdsffl is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 28
including shell env variables into C code

Hey, I'm brushing up on C code and I'm trying to incorporate the shell environmental variables into standard ansi C code.

For example I just want to do the equivalent of
--echo $PATH-- and implement that in standard ansi C code.

How would I do that?


Thanks
  #2 (permalink)  
Old 01-26-2007
milhan milhan is offline
Registered User
  
 

Join Date: Oct 2002
Location: /home
Posts: 133
Quote:
Originally Posted by bdsffl
Hey, I'm brushing up on C code and I'm trying to incorporate the shell environmental variables into standard ansi C code.

For example I just want to do the equivalent of
--echo $PATH-- and implement that in standard ansi C code.

How would I do that?

Thanks
Here it is..:

Code:
/* ShellCommsInC.c: sample program to see how shell commands can be incorporated
   in standard C ANSI code
*/

# include <stdio.h>

int main ( void )
{
     printf("\n* * * * * * * * * * * * * * * *\n") ;
     printf("This is a test for incorporating shell comm's into ANSI C code\n") ;

     system("echo") ;
     system("echo '$PATH' is: $PATH") ;
     system("echo") ;
     system("echo '$HOME' is: $HOME") ;
     system("echo") ;
     system("echo '$USER' is: $USER") ;

     printf("\nAnd so on..\n") ;
     printf("\n* * * * * * * * * * * * * * * *\n") ;

return 0 ;
}

  #3 (permalink)  
Old 01-26-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
I would just do:
puts(getenv("PATH"));
  #4 (permalink)  
Old 01-26-2007
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,794
All of the env variables:

Code:
#include <stdio.h>
int main(int argc, char **argv, char **envp)
{
	while(*envp)
	{
		printf("%s\n",*envp++);
	}
	return 0;
}

  #5 (permalink)  
Old 01-26-2007
bdsffl bdsffl is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 28
Thanks guys! This site is great!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0