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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Variable assignment in middle of a string (unix)

  • 16-04-2012 3:00pm
    #1
    Registered Users, Registered Users 2 Posts: 5,660 ✭✭✭


    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