LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to read shell built-in commands? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-read-shell-built-in-commands-4175437964/)

shivaa 11-20-2012 09:15 AM

How to read shell built-in commands?
 
Hello Friends!
How can I read content of a shell built-in command? Since such commands are not simple text files, but executable C language codes, so how can I know that code.
Thanks in advance!

acid_kewpie 11-20-2012 09:20 AM

You'd look at the source code I guess. Is that what you mean? I don't see why a built in command is any different to understanding any other command written in C

shivaa 11-20-2012 09:44 AM

Hi Chris,
I just want to check content of any simple shell built-in cmd such as "ls" or "cat".
Can we read or find it's full content in a way like we read a simple text file i.e.
Code:

cat /usr/bin/ls
Although using cat will not give any result because /usr/bin/ls isn't a simple text file. Then how can I read that?

Habitual 11-20-2012 09:52 AM

Quote:

Originally Posted by shivaa (Post 4833330)
...because /usr/bin/ls isn't a simple text file. Then how can I read that?

Neither is it a shell built-in

Code:

strings /usr/bin/ls

acid_kewpie 11-20-2012 09:54 AM

Those are NOT built in commands. they're just commands. read the source code.

Can I ask why you want to in the first place??

shivaa 11-20-2012 10:25 AM

Alright, how can we read source-code of any command available in Unix such as ls, cat, cd, ps etc.?
Quote:

Can I ask why you want to in the first place??
Chris, what do you mean, sorry I didn't understand you question?

frieza 11-20-2012 10:48 AM

first of all if you can list them in the filesystem, they are NOT 'internal' (built in) commands, internal commands would be functions within the code of the shell.
second, they are binary files, not text files.
if you want to find out how the programs do what they do, as mentioned you would have to find the source code.
if you are looking at how to USE the command, then run it's man page
Code:

$ man {command}

shivaa 11-20-2012 10:56 AM

I think my question is not clear.
I want to read source code of Unix commands such ls, cat, ps etc.
I am not concerned about their usage i.e. using man <command>.

frieza 11-20-2012 11:49 AM

fair enough
I believe those commands are part of the package 'coreutils'
http://ftp.gnu.org/gnu/coreutils/

chrism01 11-21-2012 12:13 AM

Try the suggestions here http://www.thegeekstuff.com/2010/02/...linux-command/

fakie_flip 11-21-2012 03:56 AM

Quote:

Originally Posted by shivaa (Post 4833306)
Hello Friends!
How can I read content of a shell built-in command? Since such commands are not simple text files, but executable C language codes, so how can I know that code.
Thanks in advance!

The latest bash as of right now seems to be 4.2.

http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz

There is the code.

Many distributions support a feature like this:

Code:

apt-get source bash
This will get the source code and everything else used to create the package in a Debian/Ubuntu/Mint based distro.

So you can go to the homepage of the software and look for a download link to source code or use a command for your distro like the one I gave above.

fakie_flip 11-21-2012 04:02 AM

Also, to find out what package a command belongs to:

Debian/Ubuntu:

dpkg -S /bin/ls

Redhat/Fedora:

rpm -qf /bin/ls

I tested this on my machine running CentOS.

[bullshark@alpha ~]$ rpm -qf /bin/ls
coreutils-8.4-19.el6.x86_64
[bullshark@alpha ~]$

Now you know what package that command belongs to, you can use another command provided by your distro to download the source code, or go find it on the homepage from the web.

shivaa 12-07-2012 12:05 PM

Thanks everyone! :)


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