Results 1 to 9 of 9

Thread: Update Shell command

  1. #1
    Join Date
    Sep 2014
    Beans
    7

    Update Shell command

    Hi,
    How I can access the source code of shell commands? then update it?

  2. #2
    Join Date
    Sep 2006
    Beans
    7,568
    Distro
    Lubuntu Development Release

    apt-get source

    They are all shell "commands" Which program are you interested in? You will need to know which package it is part of. Then, if you have the package 'build-dep' already installed, you can use apt-get to fetch the source. Here is how you could do it for the package 'tidy'

    Code:
    cd /tmp/
    apt-get source tidy
    That will put all the source materia for the package 'tidy' in the directory /tmp where you can work on it and then build a new package.

  3. #3
    Join Date
    Sep 2014
    Beans
    7

    Re: Update Shell command

    the question in another words; how i can for example see the source code of cp command?
    how i can modify it?

  4. #4
    Join Date
    Mar 2010
    Location
    Metro-ATL; PM free zone.
    Beans
    Hidden!
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Update Shell command

    Quote Originally Posted by mahmoud7 View Post
    Hi,
    How I can access the source code of shell commands? then update it?
    Lars could be interpreting this correctly or perhaps you just want to edit a shell script? If the script was installed through a package via the package manager, then follow what Lar's says above. Modifying the commands used inside most shell scripts is something left to a C programmer, almost always. Most commands called by shell scripts are located in /bin or /usr/bin and are compiled C programs.

    OTOH, you may not want to alter any compiled programs and just want to tweak the script itself? If the script is located somewhere on the system - use "which {name-of-program}" to find where it is and edit away. It is a good idea to make a backup of the file before you start and to not make the changes for everyone on the system - just for you by renaming the script and putting it into your personal ~/bin/ directory. At least until it has been thoroughly tested. Most pre-installed programs on a system are used by many other tools on the system, so altering the behavior is not a good idea.

    If you can clarify more about this, Lars and I can be helpful - probably.

    Update - seeing the posts below this one - seems like Lars understood the desire perfectly.
    Last edited by TheFu; October 20th, 2014 at 01:45 PM.

  5. #5
    Join Date
    Sep 2006
    Beans
    7,568
    Distro
    Lubuntu Development Release

    Re: Update Shell command

    For 'cp' you need to find out which package it is in:

    Code:
    dpkg -S /bin/cp
    That shows it is in 'coreutils', so you can grab the source for coreutils. Here is how it would be for Ubuntu 14.04.1 LTS:

    Code:
    cd /tmp/
    apt-get source coreutils
    cd coreutils-8.21/
    That assumes you also have the packge 'dpkg-dev' already installed because you need it for working with the source packages.

    Then you can look around in that directory for the source for 'cp'.

  6. #6
    Join Date
    May 2010
    Location
    Tewkesbury uk
    Beans
    7,887
    Distro
    Ubuntu Development Release

    Re: Update Shell command

    Hi

    Just a addendum to what Lars said - and assuming you want to play with a bit of C code - you may want to check if the command is a shell builtin or not.

    Code:
    matthew-laptop:/home/matthew:7 % type echo
    echo is a shell builtin
    matthew-laptop:/home/matthew:7 % type cp
    cp is /bin/cp
    matthew-laptop:/home/matthew:7 %
    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

  7. #7
    Join Date
    Mar 2010
    Location
    Metro-ATL; PM free zone.
    Beans
    Hidden!
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Update Shell command

    I hadn't looked at the C code for this stuff in ... er ... 20+ yrs. It has changed!

    cp.c --> do_copy() --> copy.c --> copy_reg() to handle the real byte-by-byte stuff (generally - there are many other paths possible).

    Lots of stuff around permissions, SElinux, links, symlinks, acls, recursive dirs ---- very interesting. Interesting to see they optimize for the memory page size and recognize performance issues with really deep recursive copies.

    Personally, I'd be afraid to alter this code ... I'm more likely to modify the kernel network driver to modify things coming or going on the wire (which I've done before). That code actually modified my resume text and I'd forgotten my driver changes were still active. It replaced a commonly known computer OS vendor corporate name with a commonly used, non-flattering version. Not good for the job search.

    Anyway - excellent question and good, helpful, answers. Very cool!

  8. #8
    Join Date
    Sep 2014
    Beans
    7

    Re: Update Shell command

    thanks you all, i had access the source code and add printf statement to its main function.
    now how i do compile so when run command it will print the statement ?

  9. #9
    Join Date
    May 2010
    Location
    Tewkesbury uk
    Beans
    7,887
    Distro
    Ubuntu Development Release

    Re: Update Shell command

    Hi

    Quote Originally Posted by mahmoud7 View Post
    thanks you all, i had access the source code and add printf statement to its main function.
    now how i do compile so when run command it will print the statement ?
    Install the build-essential package to start with

    Code:
    sudo apt-get install build-essential
    Then read the file INSTALL in the coreutils root directory.

    Install any dev dependencies required then run 'configure' with the required options and 'make'.

    I would set the install path as /opt or /usr/local if you are going to 'make install' and use the full path to call the binaries to keep then separate from your distributions binaries.

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •