Unix Shell - Re: how to search for a directory and change path to that directory

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2005 > Re: how to search for a directory and change path to that directory





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: how to search for a directory and change path to that directory
Kevin Rodgers

2005-02-09, 5:56 pm

ambs.tech@gmail.com wrote:
> how to search for a directory and change path to that directory in
> shell to be used in C program.


The find command can be used to search for a directory, in a shell
script.

But a script cannot change the current directory, unless it's invoked
with the . command (aka source) from an invoking shell. Within a C
program, you'll have to use the chdir() library call.

You could invoke the find command (via an implicit shell) from within
your C program with system(), but the problem is how to capture its
output in a char* so that it can be passed to chdir(). So you probably
need to explicitly manipulate file descriptors in your C program and
redirect the find command's output.

--
Kevin Rodgers
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com