how to concatenate two string variables (alphanumeric)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to concatenate two string variables (alphanumeric)
hello,
below my piece of code initializing two queue names variables
when iam running for loop with counter varibale it is not giving the value of queue1 and queue2 to my command.
how to solve this?
queue1=ABCD
queue2=PQRS
for i in {1..2}
do
echo "DISPLAY Q(*)"| runmqsc $queue$i
The pipe sends data via stdin. So if your utility is expecting to read that, then the pipe is the way to go. Otherwise, xargs is the way to go.
About the variables, if what you are aiming for is an indirect reference where the name of a variable is held in a second variable and the value accessed via that, then :
Code:
#!/bin/sh
queue1=ABCD
queue2=PQRS
for i in $(seq 1 2)
do
a=$(eval echo -n \$queue$i)
echo "DISPLAY Q(*) " | echo runmqsc $a
done
Also [code] [/code] will help keep your script readable.
queue1=ABCD
queue2=PQRS
for i in {1..2}
do
echo "DISPLAY Q(*)"| runmqsc $queue$i
done
When you run this for loop, you will call runmqsc twice. Once with a parameter ${queue}1, a second time with ${queue}2. If queue is not initialized, the result is runmqsc 1 followed by runmqsc 2.
To concatenate the variables:
Code:
runmqsc $queue1$queue2
If, on the other hand, you want to call runmqsc twice, with queue1 and queue2, respectively, and you absolutely need to do this in a loop, use arrays.
Code:
queue[1]=abcd
queue[2]=efgh
for i in {1..2}
do runmqsc ${queue[i]}
done
Last edited by berndbausch; 01-17-2019 at 08:05 PM.
...where you post (when asked) a small piece of a 'script', get a few suggestions, then come back asking folks to finish it for you. How about this: you take the advice you've been given thus far, put it to use in a script, and post that script back here if it doesn't work?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.