top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Is cd command is a built-in function or a script

+2 votes
79 views

We all know that cd is a built-in function of whatever shell you're using.

$ cat /usr/bin/cd
#!/bin/sh
builtin cd "$@"

Does anybody know why this file exists?

posted Sep 12, 2013 by Sheetal Chauhan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

I believe it's a backwards-compatibility thing. IIRC, System7's Bourne shell didn't have a built-in "cd" command (or several others). Some scripts probably still look for that file (and the others).

It's been superfluous for a long time, but time has proven that when you take away something like that, eventually something breaks or someone gripes about it.

answer Sep 12, 2013 by Jai Prakash
No. "cd" has always been a builtin; it does not work otherwise. Think it through.
0 votes
~]$ cat /usr/bin/cd
cat: /usr/bin/cd: No such file or directory

~]$ which cd
/usr/bin/which: no cd in
(/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/tim/.local/bin:/home/tim/bin)
answer Sep 12, 2013 by Meenal Mishra
Similar Questions
0 votes

I am looking for One Line Command or a simple script to set the 'shutdownhtml' in /var/www/html/bugzilla/data/param file.

From...

'shutdownhtml' => '',

To....

 'shutdownhtml' => 'Archiving DB and Bugzilla config... It could takes 5 min or longer.',

Did try to use "sed" but somehow the config above has Single Open quote ' , so seem like "sed" not able to do this... ??

+3 votes
+1 vote

I am running below script on sles 11 and getting different output.

#!/bin/bash
PID=$(/bin/ps aux | grep sro-rest | grep -v grep | awk '{print $2}')
echo "PID = $PID"
. /etc/rc.status
PID=$(/bin/ps aux | grep sro-rest | grep -v grep | awk '{print $2}')
echo "PID = $PID"

Output:

PID = 2453
PID =

After debugging, I get to know that once we run . /etc/rc.status then output of ps aux is getting short.
See below script for example,

#!/bin/bash
echo "Before ==================================> "
/bin/ps aux | grep java | grep -v grep
. /etc/rc.status
echo "After ==================================> "
/bin/ps aux | grep java | grep -v grep

Output :

Before ==================================>
root      2453  4.9  7.8 8496196 615020 ?      Sl   Jun05  60:31 /usr/java/jre1.8.0_77//bin/java -Djava.net.preferIPv4Stack=true -Djava.library.path=/opt/sro/lib -Dserver.port=50000 -Dspring.profiles.active=gal -jar /opt/sro/ui/lib/sro-rest-SNAPSHOT.jar
After ==================================>
root      2453  4.9  7.8 8496196 615020 ?      Sl   Jun05  60:31 /usr/java/jre1.8.0_77//bin/java -Djava.net.preferIPv4Stack=true -Djava.l

Can anyone explain why different behavior for the same command?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...