How to manipulate a string, variable in shell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhimok
    New Member
    • Jul 2010
    • 3

    How to manipulate a string, variable in shell

    Hei everyone!

    I have this variable in shell containing paths separated by
    a space:

    Code:
    LINE="/path/to/manipulate1 /path/to/manipulate2"
    I want to add additional path string in the beginning of the string and as well right after the space so that the variable will have the result something like this:

    Code:
    LINE="/additional/path1/to/path/to/manipulate1 /additional/path2/to/path/to/manipulate2"
    Any help appreciated
    Thanks in advance
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Do you want o to add two different directories?
    /additional/path1
    /additional/path2
    Do this path can be somehow calculated from original paths, is this correlation ok
    Code:
    /path/to/manipulate1 -> add /additional/path1
    /path/to/manipulate2 -> add /additional/path2
    /path/to/manipulate3 -> add /additional/path3
    ...

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      To add paths to the variable in the shell, simply do the following:

      Code:
      export LINE = "$LINE /new/path/1 /new/path/2"
      You first put the current variable in the list and then add any after it.

      Regards,

      Jeff

      Comment

      • kwarnke
        New Member
        • Sep 2007
        • 1

        #4
        $ LINE="/path/to/manipulate1 /path/to/manipulate2"
        $ set -- $LINE
        $ LINE="/additional/path1/to$1 /additional/path2/to$2"

        Comment

        Working...