Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i have the full pathname with C function

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
in shell script unix I do
echo $(cd $(dirname "$name");pwd)/$(basename "$name")

is it possible in C??

escuse me for my bad english, I'm french
 
Exactly how is that different to this?
Code:
echo $name

I mean the 'cd' happens in a sub-shell, so the side-effect of that is lost.

--
 
$ pwd
/usr/bin
$ name="sh"
$ echo $(cd $(dirname "$name");pwd)/$(basename "$name")
/usr/bin/sh
$ echo $name
sh


do you anderstand??
 
So it's this then?
Code:
echo `pwd`/$name

Or were you hoping to get "/usr/bin/sh" even when the current directory isn't /usr/bin? This sounds exactly like the "which" command.

What other examples of pwd and $name do you have to worry about?

Stating the problem rather than your current answer would be a help as well.

--
 
i want a C function that can translate any relative name (like ../bin/sh) into absolute name (like /usr/bin/sh)

i want a C solution if it's possible
=====================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top