Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell source code

Status
Not open for further replies.

drimades

IS-IT--Management
Nov 8, 2004
221
MK
I need the shell source code (in C) for Linux. I found a sh-utils directory with different source code files in C such as man, tty, pwd source codes. Still I can't find the main shell source code that manages the calls to the various commands (man, tty, pwd, etc.)
 
Which shell, do you mean bash? There are a few different shells out there. I'm sure if you searched for "bash source" you would fine it...

Annihilannic.
 
It's bash. I've found a file "shell.c" but I'm not sure this one is the file for the shell? Is it?
 
bash is a complex piece of software that will consist of many source files. Why exactly are you looking for the source anyway?

Annihilannic.
 
It's at
Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I'm looking for the source to understand how it works and to know the dependencies between the different pieces of code and how are they related to each other (calls, includes, etc.).
 
This is the main of tty command:

main (int argc, char **argv)
{
char *tty;
int optc;

program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

close_stdout_set_status (3);
atexit (close_stdout);

silent = 0;

while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
{
switch (optc)
{
case 0:
break;

case 's':
silent = 1;
break;

case_GETOPT_HELP_CHAR;

case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);

default:
usage (2);
}
}

if (optind != argc)
error (0, 0, _("ignoring all arguments"));

tty = ttyname (0);
if (!silent)
{
if (tty)
puts (tty);
else
puts (_("not a tty"));
}

exit (isatty (0) ? 0 : 1);
}


Can someone briefly describe how it works?
 
It's a pretty basic C programme... if you don't understand C then you had better go do some reading because it is far too big a topic to cover in a post here!

Do you have any questions about specific parts of it?

Annihilannic.
 
Kernighan and Ritchie 'The C programming language' is generally regarded as the bible on the subject. Don't be put off by the fact that it is a slim volume when compared with those doorstep-sized books that purport to teach you all you need to know in a weekend.

The only problem is that it makes depressing reading for a novice or intermediate who is having delusions of adequacy about their coding skills... [smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top