You are not logged in.

#1 2011-09-28 06:48:06

kd0bpv
Member
Registered: 2010-11-23
Posts: 26

which: no cd in $PATH

I noticed something odd. When I tried to change into a directory (not / as shown below), I was denied access. Wanting to avoid su'ing, I tried and got this:

[mark@ares ~]$ sudo cd /
Password: 
sudo: cd: command not found

I've not tried that before, and I didn't really expect it to work. But I still thought it was odd, so I immediately tried and got:

[mark@ares ~]$ which cd
which: no cd in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/kde/bin:/usr/bin/core_perl:/opt/qt/bin)
[mark@ares ~]$ type cd
cd is a shell builtin

Is this normal for Arch Linux? Is there a binary 'cd' that I can install to replace the built-in? It's not a major issue for me, as I do have the option of su'ing, but I do subscribe to the "everything is a file" idea, and much prefer binaries over built-ins. I looked into the extra/cdargs package, and ruled it out, as it has features I'd never use, and even the author admits the code is horribly written.

Offline

#2 2011-09-28 06:58:06

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: which: no cd in $PATH

What an interpretation of "everything is a file"!

For the lulz, save this in $PATH as an executable file named "cd",

#!/bin/sh
builtin cd "$@"
$SHELL

Edit:
OK, I'll be patient.
Understand that for `sudo` or any other command that is not a shell builtin, when the command terminates, the shell picks up where it left off before the command was run (of course, the shell's current working directory won't change). As such, `cd` must be a shell builtin; otherwise, when `cd` terminates, the shell is back to the same old current working directory. In other words, a child process (i.e. an external command) can't change the working directory of the parent process (i.e. the shell).

Last edited by lolilolicon (2011-09-28 07:50:03)


This silver ladybug at line 28...

Offline

#3 2011-09-28 07:02:26

FarmerF
Member
From: Netherlands
Registered: 2009-06-08
Posts: 76

Re: which: no cd in $PATH

Cd is indeed a shell builtin, not only on Arch. This should not case any failure. Am I correct in assuming that cd does work in most cases but gave an error with one or a few directories? In that case list the permissions and see if there is anything wrong there. If you need help with that post the result of the following two commands:

ls -al  /path/to/directory (only the . entry is relevant)
id

You can change the actual path in the results if you prefer. The relevant part is the first part wicht a sequence of rwx's


If all cd commands fail then check what shell you are using. You can post the results of

cat /etc/passwd

Only the lines for your user and root are relevant and then only the part after the last double colon.

Offline

#4 2011-09-28 07:09:40

oboedad55
Member
From: Baku
Registered: 2011-04-05
Posts: 392

Re: which: no cd in $PATH

OK, I mucked around with this. Here's what I got;

[dlouhy@archdad home]$ sudo cd /
sudo: cd: command not found
[dlouhy@archdad home]$ cd /
[dlouhy@archdad /]$ 

Found this;
https://bbs.archlinux.org/viewtopic.php?pid=449613

And this;
http://www.f15ijp.com/2010/09/13/sudo-c … not-found/

Last edited by oboedad55 (2011-09-28 07:18:13)


Registered Linux user #436067

Offline

#5 2011-09-28 07:26:03

kd0bpv
Member
Registered: 2010-11-23
Posts: 26

Re: which: no cd in $PATH

@lolilolicon

lol. Like I said. It's not that big of a deal, especially considering I've been using various linux distributions for the last decade or so and never before noticed this. But that is an interesting tip for if I come across something similar that is an actual issue, which I think is unlikely.

And yes, I'm aware that "everything is a file" primarily refers to hardware (ie: /dev). I just tend to take it a small step further, and prefer that essential commands also be stand-alone files (binaries/executables) that are shell-independent. It would allow for greater modularity, and thus greater flexibility... Two major things that make unix and linux so powerful and stable. smile

Last edited by kd0bpv (2011-09-28 07:27:09)

Offline

#6 2011-09-28 07:40:33

kd0bpv
Member
Registered: 2010-11-23
Posts: 26

Re: which: no cd in $PATH

FarmerF wrote:

Cd is indeed a shell builtin, not only on Arch. This should not case any failure. Am I correct in assuming that cd does work in most cases but gave an error with one or a few directories? In that case list the permissions and see if there is anything wrong there. If you need help with that post the result of the following two commands:

ls -al  /path/to/directory (only the . entry is relevant)
id

You can change the actual path in the results if you prefer. The relevant part is the first part wicht a sequence of rwx's


If all cd commands fail then check what shell you are using. You can post the results of

cat /etc/passwd

Only the lines for your user and root are relevant and then only the part after the last double colon.

You are correct that most cd commands work. The directory I was trying to enter was /etc/polkit-1/localauthority/, which is not a directory a regular user would normally have any business in anyways. I was just following an article in the Arch wiki to learn more about how the policy kit works. From what I understand of the policy kit, I would not want to change the permissions of that folder anyways, as doing so could open up security holes.

So, as I said, it's not important. It's just something I've not noticed before and was wondering if that is normal, and if there was a binary version that could be installed, per my personal preferences.

Thanks for the info though. smile

Last edited by kd0bpv (2011-09-28 07:49:55)

Offline

#7 2011-09-28 07:48:21

kd0bpv
Member
Registered: 2010-11-23
Posts: 26

Re: which: no cd in $PATH

lolilolicon wrote:

Edit:
OK, I'll be patient.
Understand that `sudo` is just a command- just like every other command that is not a shell builtin, when the command terminates, the shell picks up where it left off before the command was run (of course, the current working directory won't change for the shell). As such, `cd` must be a shell builtin; otherwise, when `cd` terminates, the shell is back to the same old current working directory. In other words, a child process (i.e. an external command) can't change the working directory of the parent process (i.e. the shell).

Heh. Yeah. I know. I just didn't think of it at that time. Being really tired and trying to learn the deep, fine-grained workings of a system don't mix. LOL. Again, the main reason I was posting is because I hadn't noticed that cd was a built-in part of bash before and was wondering if it was normal, or a quirk of Arch.

Last edited by kd0bpv (2011-09-28 07:48:40)

Offline

#8 2011-09-28 07:51:24

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,543

Re: which: no cd in $PATH

You can execute builtin shell commands with sudo using something like this

sudo sh -c "cd /etc/polkit-1/localauthority/; pwd"

Last edited by skunktrader (2011-09-28 07:52:17)

Offline

#9 2011-09-28 14:25:18

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: which: no cd in $PATH

kd0bpv wrote:

Wall of text

cd'ing with sudo is sort of useless in the first place, use sudo -s or sudo -i instead.
edit: even after you ender the directory with sudo you wouldn't be able to do anything really usefull in there without root privs.

Last edited by Mr.Elendig (2011-09-28 14:27:53)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

Board footer

Powered by FluxBB