Operating System - HP-UX
1834714 Members
2144 Online
110069 Solutions
New Discussion

What is "/usr/bin/cd" for ?

 
SOLVED
Go to solution
Art Mehlman
Frequent Advisor

What is "/usr/bin/cd" for ?

I wrote a script to be executed by CA Workload manager. I was being careful to use fully qualified path names. When I did a "which cd" the response was /usr/bin/cd, so I placed that in my script "/usr/bin/cd /dev/vg_opsbcv" .
Lo and behold the chown command after the above command didn't change the right files.

Of course, I now remember that cd is built-in to the shell, not an executable. What I can't figure out is what the cd script in /usr/bin is useful for? It looks like it shells out and does the cd, then exits that shell, so the parent shell doesn't see the cd. Any explanation what the /usr/bin/cd script is for would be helpful
13 REPLIES 13
Patrick Wallek
Honored Contributor

Re: What is "/usr/bin/cd" for ?

Have a look at the file /usr/bin/cd.

It appears to just be a script that calls the shells cd.

# file /usr/bin/cd
/usr/bin/cd: commands text

# cat /usr/bin/cd

#!/usr/bin/sh
# @(#)B.11.11_LR

# This is the executable version of cd implemented using the
# posix shell built-in cd command.

cd "$@"
exit $?
Uday_S_Ankolekar
Honored Contributor

Re: What is "/usr/bin/cd" for ?

Hi,

cd is from change directory and it's a posix built-in shell command. The /usr/bin directory has all these built-in commands.

-USA..
Good Luck..
James R. Ferguson
Acclaimed Contributor

Re: What is "/usr/bin/cd" for ?

Hi Art:

What you observed is expected. Take a look at the man pages for 'cd':

"cd exists only as a shell built-in command because a new process is created whenever a command is executed, making cd useless if written and processed as a normal system command. Moreover, different shells provide different implementations of cd as a built-in utility."

Thus, the extenal command exists to provide a standard should the need exist.

Regards!

...JRF...
Roger Baptiste
Honored Contributor

Re: What is "/usr/bin/cd" for ?


when you use "'cd"" - the
shell''s built in CD command
is excuted. It does not
call /usr/bin/cd.
Do this test
# mv /usr/bin/cd /usr/bin/cd.old
# the cd command will still work.

My guess is it is just a wrapper for future compatibility use.

Being a shell builtin, there
is no need to specify the
path of it in your scripts.

-raj
Take it easy.
Darrell Allen
Honored Contributor

Re: What is "/usr/bin/cd" for ?

Hey Art, I'm with you. I'm not seeing a pratical use for /usr/bin/cd. When I run it in the shell I'm left in the dir where I started. When I exec it or use ". /usr/bin/cd" it exits my shell.

Can anyone give us a practical use for /usr/bin/cd?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Frank Slootweg
Honored Contributor

Re: What is "/usr/bin/cd" for ?

/usr/bin/cd indeed has very limited use. But, as always, when in doubt, Real The Fine Manual! :-)

The cd(1) manual page gives an example with find(1) and its -exec option.

Another, perhaps slightly more useful, example in that manual page is "Another usage of cd as a stand-alone command is to obtain the exit
status of the command.".
Volker Borowski
Honored Contributor

Re: What is "/usr/bin/cd" for ?

... aaah, never noticed it is a "Fine" manual :-)

V.
Darrell Allen
Honored Contributor

Re: What is "/usr/bin/cd" for ?

Gold star for Frank! That's a use for /usr/bin/cd though I wonder how often it's ever used.

Read the manual? And miss all this fun? Just kidding!

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Art Mehlman
Frequent Advisor

Re: What is "/usr/bin/cd" for ?

Frank,
Thanks for the gentle reminder and the answer.
I have been using cd for quite a while and took the manual and the command for granted.
Just another perplexing day on the job.
Wodisch
Honored Contributor

Re: What is "/usr/bin/cd" for ?

...and I always thought it would be a "funny" manual... W.
Frank Slootweg
Honored Contributor
Solution

Re: What is "/usr/bin/cd" for ?

You are welcom, Art. Just a minor point: I think you made an error when assigning points, or do you consider the question (still) unanswered? If so, why?
Art Mehlman
Frequent Advisor

Re: What is "/usr/bin/cd" for ?

Frank,
I did make a mistake when assigning points to your answer. I emailed the forums folks and they say that there is no way to change the point value once it is assigned. I hope by assigning 10 to your latest question, that will rectify the mistake. Sorry about that.
brian_31
Super Advisor

Re: What is "/usr/bin/cd" for ?

I hope you have got enough answers. Just to confirm you can always use whence -v *whatever* to find out exactly

Thanks
Brian