Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I want to create a loop to show the content of these variables:
for (( X = 1; X <= 3; X++ ))
This returns me "1", "2" and "3" instead of "STRING1", "STRING2" and "STRING3". I know I'm doing something wrong, but I can't figure what. I read at bash man pages something about variable expansion, but couldn't find the corret way to make this work. Can someone help me?
As an alternative approach instead of using arrays, you can try something like:
IFS=" \t\n" #this is usually the default, makes $mySTRINGS be split on spaces, tabs and newlines in the
#for-loop. IFS should thus at least contain " " (space) to split the strings on the spaces...
mySTRINGS="STRING1 STRING2 STRING3"
for str in $mySTRINGS; do
Your approach failed simply because $VAR is empty/undefined and your echo interpreted $VAR and $X as separate variables, not as the variable $VARn with n=1,2,3.
theNbomr and timmeke, you're both correct, but in fact this is not my case. I would like to know how to expand the content of a variable using another variable to reference it's name, being an array or not, like in this case:
This returns "1" instead of "STRING1" since $VAR doesn't exist. My intention is: echo the content of "$VAR1" using $X as parameter. I don't know if I'm being clear, let me know.