- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- differnece between "cd" and "/usr/bin/cd"
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2004 08:03 PM
тАО02-18-2004 08:03 PM
differnece between "cd" and "/usr/bin/cd"
if I type :
cd /var/tmp ; pwd
The answer is : /var/tmp
If I type :
/usr/bin/cd /var/tmp ; pwd
The answer is : /tmp ( which was my previous working dir)
which cd >> /usr/bin/cd
How do you explaine this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2004 08:09 PM
тАО02-18-2004 08:09 PM
Re: differnece between "cd" and "/usr/bin/cd"
"/usr/bin/cd" is a binary that changes your working directory. It's default behavior is to show you the real directory you are in.
My guess is that you have /var/tmp symbolically linked to /tmp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2004 08:20 PM
тАО02-18-2004 08:20 PM
Re: differnece between "cd" and "/usr/bin/cd"
It's hard think of any use for /usr/bin/cd, but try "man cd" if you're interested - on 11i, it gives an example of the use of "cd" in a find command which might equate to /usr/bin/cd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2004 08:25 PM
тАО02-18-2004 08:25 PM
Re: differnece between "cd" and "/usr/bin/cd"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2004 07:48 AM
тАО02-19-2004 07:48 AM
Re: differnece between "cd" and "/usr/bin/cd"
as said "cd" is internal to the shell and therefor does not deliver an exit code.
In case you create a script and want to validate, if a "cd target_dir" will succeed, you can use the binary in an if-statement and you will have existence and permission-check all in one.
Bad script:
cd /tmp/mydir
rm *
Now just assume /tmp/mydir is not accessible for whatever reason...... Directory where you have been before will be destroyed.
Better script:
if /usr/bin/cd /tmp/mydir
then
do what you like here
else
do what you not like here
fi
I have to say I never really used that, but I remember a school-lesson that said it should be used that way.
May be you can let us know if you tried it out ?
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2004 06:33 PM
тАО02-22-2004 06:33 PM
Re: differnece between "cd" and "/usr/bin/cd"
Using cd in my scripts works.
Is there a list of the internal commands ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2004 06:38 PM
тАО02-22-2004 06:38 PM
Re: differnece between "cd" and "/usr/bin/cd"
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2004 07:19 PM
тАО02-22-2004 07:19 PM
Re: differnece between "cd" and "/usr/bin/cd"
You typed:
'as said "cd" is internal to the shell and therefor does not deliver an exit code.'
That is false.
Supose /kkad doesn't exist:
# cd /kafd; echo "return code is $?"
/usr/bin/sh: /kafd: not found
return code is 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2004 04:30 AM
тАО02-23-2004 04:30 AM
Re: differnece between "cd" and "/usr/bin/cd"
thank you for showing this.
In fact I took this from "man cd"
:
Another usage of cd as a stand-alone command is to obtain the exit status of the command.
:
And assumed (wrongly) that the internal one does not deliver an exit code.
May be this manpage-info is outdated and it was so in earlier days.
So the only difference is, that the executable creates a real new subprocess, thus making this processing diffrent:
# cd /
# if cd /tmp; then echo I could [and did] change to /tmp; else echo Did not work; fi
I could [and did] change to /tmp
# pwd
/tmp
# cd /
# if /usr/bin/cd /tmp; then echo I could [and did not] change to /tmp; else echo Did not work; fi
I could [and did not] change to /tmp
# pwd
/
#
Confusing :-)
Volker