LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Unix source code (https://www.linuxquestions.org/questions/programming-9/unix-source-code-184937/)

Scrag 05-23-2004 04:37 PM

Unix source code
 
Anybody know where I can get source code for basic unix commands, like "cd" "ls", etc.

Thanks!

:study:

xlord 05-23-2004 04:41 PM

They are just compiled binary files.. you can do them your self, in c/python/perl/bash not hard

Dark_Helmet 05-23-2004 04:49 PM

I think they are contained in the coreutils package (search for "coreutils" on freshmeat.net).

I'm not absolutely positive they are part of that package, but it's likely to contain many basic utilities. Also, be aware that some of those commands are "builtin commands" for bash/tcsh/whatever. That means you would have to crack open your shell's source code to see how they implement it, because there would be no corresponding utility.

jtshaw 05-23-2004 04:51 PM

http://www.gnu.org/directory/fileutils.html

jlliagre 05-23-2004 08:38 PM

"cd" cannot be a standalone command, as useless when not a builtin.

jtshaw 05-23-2004 09:13 PM

Ya, cd is usually bultin to the shell. ls, dir, ect. are in the gnu fileutils package I linked to above.

jlliagre 05-24-2004 09:41 AM

well, cd is not usually but *always* a shell builtin !

Hko 05-24-2004 03:49 PM

True. "cd" is one of very few commands (the only?) you can be sure about that it is a shell built-in.

infamous41md 05-24-2004 04:02 PM

and umask iirc

jlliagre 05-25-2004 02:28 AM

Actually, there are plenty of builtin commands that couldn't technically be externalized like:
declare, set, unset, readonly, local, read, shift, dirs, popd, pushd, getopts, function, [un]alias, typeset, history, fg, bg, jobs, trap, eval, export, ulimit and "." (source).

Structural commands like "for", "select", "case", "return", "exit", "break" and the like can also only be embedded in the shell.

btw, cd was the first builtin command to be integrated in a unix shell (in the early seventies ...):

from: http://cm.bell-labs.com/cm/cs/who/dmr/hist.html

Quote:

Although the multiple-process idea slipped in very easily indeed, there were some aftereffects that weren't anticipated. The most memorable of these became evident soon after the new system came up and apparently worked. In the midst of our jubilation, it was discovered that the chdir (change current directory) command had stopped working. There was much reading of code and anxious introspection about how the addition of fork could have broken the chdir call. Finally the truth dawned: in the old system chdir was an ordinary command; it adjusted the current directory of the (unique) process attached to the terminal. Under the new system, the chdir command correctly changed the current directory of the process created to execute it, but this process promptly terminated and had no effect whatsoever on its parent shell! It was necessary to make chdir a special command, executed internally within the shell. It turns out that several command-like functions have the same property, for example login.


All times are GMT -5. The time now is 03:10 PM.