Results 1 to 7 of 7

Thread: Can I add the another source in sources.list by command line?

  1. #1
    Join Date
    Oct 2011
    Beans
    2

    Can I add the another source in sources.list by command line?

    If I don't want to edit the sources.list file by vi(m), could I add the source by command line to import the specific source in the sources.list file
    I want to add the command to the sell script, please give me the suggestion...thanks

    for example:
    Could I add below sources into sources.list by one line command
    Last edited by goddesschi; April 13th, 2013 at 05:33 AM.

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,743
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Can I add the another source in sources.list by command line?

    Hi goddesschi.

    I see a couple of alternatives:

    Using sed:
    Code:
    #!/bin/bash
    sed -i '$ a\
    \
    # Inserted by this because of that.\
    deb http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main\
    deb-src http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main' /etc/apt/sources.list
    Or using bash's echo:
    Code:
    #!/bin/bash
    echo "" >> /etc/apt/sources.list
    echo "# Inserted by this because of that." >> /etc/apt/sources.list
    echo "deb http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main" >> /etc/apt/sources.list
    echo "deb-src http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main"  >> /etc/apt/sources.list
    Since you are appending content to a root's owned file you would need to run this using sudo:
    Code:
    sudo either_script.sh
    Hope it helps. Let us know how it goes.
    Regards.
    Last edited by papibe; April 13th, 2013 at 06:22 AM. Reason: added a blank line before adding content

  3. #3
    Join Date
    Mar 2011
    Location
    Romania
    Beans
    145
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can I add the another source in sources.list by command line?

    actually, there is no need to add the source by editing the source list. instead, you can add a PPA by add a line in source of "software source"
    so: ubuntu software center--> edit-->software source-->other software-->add
    Attached Images Attached Images
    dell inspiron 1521, AMD Turion, ATI mobility radeon x1270.

  4. #4
    Join Date
    Oct 2005
    Beans
    29
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can I add the another source in sources.list by command line?

    One line:

    Code:
    echo -e '\ndeb http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main\ndeb-src http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main ' | sudo tee -a /etc/apt/sources.list
    Explanation:
    The command above can be divided into two parts: the 'echo' and the 'tee'.
    1. The 'echo' will send your sources to the stdout. The -e switch will make it interpret escape sequences - such as \n - correctly.
    2. The result of 'echo' above is piped to 'tee' below.
    3. The 'tee' will copy sources lines from the pipe, and write that into /etc/apt/sources.list. The -a switch will make it append the lines into the file, instead of overwriting it.

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Can I add the another source in sources.list by command line?

    Instead of editing the main sources.list file you should create your own .list file in /etc/apt/sources.list.d

    For adding multiple lines, I'd probably use a here string:
    Code:
    cat << EOF > /etc/apt/sources.list.d/my-ppa-repo.list
    # short description
    
    deb http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main
    deb-src http://ppa.launchpad.net/shiki/mediainfo/ubuntu precise main
    EOF

  6. #6
    Join Date
    Oct 2011
    Beans
    2

    Re: Can I add the another source in sources.list by command line?

    Thanks a lot, every friends.
    Could I ask another question about sed

    if I want to replace the sentence '/' to '/home', how to type the command

    I try to type the below command, but it can't work...
    sed -i 's/"'"\/"'"/"'"\/home\/"'"/g' config.php
    Last edited by goddesschi; April 13th, 2013 at 01:58 PM.

  7. #7
    Join Date
    Apr 2012
    Beans
    7,088

    Re: Can I add the another source in sources.list by command line?

    imo the easiest way is to avoid escaping or quoting the slash altogether by using a different separator for the sed substitution command e.g. with | as separator

    Code:
    $ echo '/my/dir' | sed 's|/|/home/|'
    /home/my/dir

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
  •