Results 1 to 3 of 3

Thread: Problem while replacing a directory with some variable

  1. #1
    Join Date
    Mar 2013
    Beans
    1

    Problem while replacing a directory with some variable

    I have written some script under the path root/c4/build and in that script I have mentioned the path /home/cdot/c4. I want to replace /home/cdot with some variable. I have to make a script in the root directory so that I could replace the path /home/cdot inside root/c4/build with the variable. Can you plaese help me?

    Thanku

  2. #2
    Join Date
    Aug 2011
    Location
    52° N 6° E
    Beans
    2,196
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Problem while replacing a directory with some variable

    You want a script that modifies a script? Try using sed:
    Code:
    sudo sed -i s:/home/cdot:your_variable:g /root/c4/build

  3. #3
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Problem while replacing a directory with some variable

    You also may consider passing the path to the script as parameter on command line if you need a more flexible solution. Just change the line suggested by Impavidius like this:
    Code:
    sudo sed -i 's:/home/cdot:$1:g' /root/c4/build
    You also may need to quote it properly if there's possibility of the parameter containing space characters.

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
  •