Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Variable assignment in middle of a string (unix)

Options
  • 16-04-2012 4:00pm
    #1
    Registered Users Posts: 5,559 ✭✭✭


    Hi folks, some code i have to assign some variables called file, file2, file3 and file4

    files()
    {
    template=$2
    file=template$template.xml
    file2=template$templateSL3.xml
    file3=template$templateSL3toSL2.xml
    file4=template$templateSL2ToSL1.xml
    }



    But when i run it

    files test lienb0583

    , my output becomes


    template.xml


    instead of the desired

    templatelienb0583.xml

    Can you advise what im doing wrong


Comments

  • Registered Users Posts: 255 ✭✭boblong


    Is this what you need?
    
    files()
    {
    template=$1 #in here this is $1
    file=template${template}.xml
    file2=template${template}SL3.xml
    file3=template${template}SL3toSL2.xml
    file4=template${template}SL2ToSL1.xml
    
    echo "$file $file2 $file3 $file4"
    }
    
    #call the function
    files $2 #but out here this is $2
    
    #run like:
    # sh shellyoke.sh test lienb0583
    
    


Advertisement