Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Variable assignment in middle of a string (unix)

  • 16-04-2012 04:00PM
    #1
    Registered Users, Registered Users 2 Posts: 5,762 ✭✭✭


    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, Registered Users 2 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