Una de las grandes ventajas de los lenguajes interpretados es que podemos almacenar en una variable el nombre de otra variable y trabajar con su valor. ¿Punteros? Bueno, al final es parecido a la utilización de punteros en C, aunque aquí podemos hacer referencia por el mismo nombre de la variable incluso, previo filtrado y con mucho cuidado, preguntarle al usuario el de la variable para trabajar con ella.
Esto nos puede dar mucha flexibilidad en nuestro código. Por ejemplo, yo lo he utilizado para perfeccionar mi script de lectura de ficheros de configuración al que le podemos pasar también el nombre de la variable donde almacenar la configuración.
Tabla de contenidos
Arrays con nombre dinámico
En Bash, acceder a una variable cuyo nombre está contenido dentro de otra variable es sencillo, podemos hacerlo llamando a ${!NOMBREDEVARIABLE}. Podemos ver un ejemplo en el post referenciado.
El problema es que cuando son arrays no es tan inmediato. El objetivo es que, teniendo una variable que contiene el nombre del array podamos acceder a su información de una forma sencilla. Y El problema aquí viene en la versión de Bash que estemos utilizando. En este caso debemos hacerlo de una forma u otra dependiendo de si utilizamos una versión inferior a la 4.3 (más o menos salió en 2014) o si tenemos una versión posterior.
Ejemplo para Bash < 4.3
Lo siento, mira que no me gusta utilizar eval, pero claro, para estas versiones del intérprete necesitamos crear una cadena de caracteres con la llamada que vamos a hacer y luego evaluar dicha cadena de caracteres. Esto nos dará el valor que buscamos. Por ejemplo:
1 2 3 4 5 6 | MIARRAY=("cero" "uno" "dos" "tres") REFERENCIA="MIARRAY" # Lo que necesitamos es acceder a cada uno de los elementos de MIARRAY a través de REFERENCIA. eval echo \${$REFERENCIA[2]} |
Si os fijáis, al construir la cadena. El primer símbolo de dólar ($) lo escapamos con la barra para que no se interprete. El que sí tiene que interpretar es el segundo, para que $REFERENCIA se transforme en el nombre del array.
Lo podemos hacer con arrays asociativos también sin problema, pero es algo complicado y realizamos demasiadas tareas para hacer referencia a una variable. Además no queda muy elegante o intuitivo tener que escapar un dólar y otro no.
Ejemplo para Bash >= 4.3
Para estas versiones, disponemos de un modificador en la orden declare (también llamada typeset) a través del cual podemos crear una variable de referencia que se comportará exactamente igual que nuestro array:
1 2 3 4 | MIARRAY=("cero" "uno" "dos" "tres") declare -n REFERENCIA="MIARRAY" echo ${REFERENCIA[2]} |
Además, de esta forma, el nombre de la variable puede venir dado en otra variable, con lo que podemos permitir que el usuario especifique el nombre de variable. Eso sí, con mucho cuidado.
Foto principal: Ruben Ortega
Today’s Wordle is one of my favorite parts of the day, so it’s a paradox that happiest when we solve the puzzle quickly. My mornings are hectic. Today’s wordle is moderately challenging because of uncertainty. Today’s Wordle took the world by storm when it launched, and has kept players glued to their phone screens ever since.
Esta muy bien! Puedes seguir viendo cursos aqui https://donovanicaz91605.blognody.com/
Ok! Me pasare ahora por tu pagina. Puedes visitar https://wopi.es/las-mejores-joyas/
Esto es excelente. mira mi post sobre como ganar seguidores en tik tok http://www.opensource.platon.org/forum/projects/viewtopic.php?p=12573847#12573847
Thank you for your reasonable criticism. My neighbor and I are preparing to do some research on that temple run. We got a good book about it from our local library and most of the books are not as impactful as your information.
sportbootführerschein binnen und see, sportbootführerschein binnen prüfungsfragen, sportbootführerschein binnen kosten, sportbootführerschein binnen online, sportbootführerschein binnen wo darf ich fahren, sportbootführerschein binnen berlin, sportbootführerschein binnen segel, sportbootführerschein kaufen, sportbootführerschein kaufen erfahrungen, sportbootführerschein kaufen schwarz, sportbootführerschein see kaufen, sportbootführerschein binnen kaufen, sportbootführerschein see kaufen ohne prüfung, bootsführerschein kaufen, bootsführerschein kaufen polen, bootsführerschein kaufen erfahrungen, bootsführerschein online kaufen, bootsführerschein tschechien kaufen. https://sportbootfuhrerscheinkaufen.com/
sportbootführerschein see
I am continually looking online for articles that can facilitate me. Thank you! 토토사이트
I stumbled on this while browsing on google I’ll be sure to come back. thanks for sharing. https://therowdylender.com/
What’s up colleagues, its enormous post regarding educationand entirely defined, keep it up all the time. 메이저사이트
F*ckin¦ Have you ever thought about including a little bit more than just your articles? 먹튀검증
This technique offers valuable flexibility in Bash scripting, but you should choose the approach that best fits your version and coding style. | [url=https://www.mcallendrywall.com]https://www.mcallendrywall.com[/url]
This technique offers valuable flexibility in Bash scripting, but you should choose the approach that best fits your version and coding style.
Monkey Type is an engaging and interactive website that offers educational games, videos, and books for kids of all ages. It covers a wide range of subjects including math, reading, science, and problem-solving. With its entertaining content and educational focus, Funbrain provides a fun learning experience for children while reinforcing key academic skills.
Monkey type
https://www.area-codes.us/347-area-code/
347 Area code is a New York City area code covering the Bronx, Queens, Brooklyn. This area code was assigned on February 19, 1999. It went live on October 1, 1999. 347 Area code is a general purpose code. Service area 347 overlaps with area codes 718 917 929. The dialing pattern for local calls within the same NPA (area code) is 1+10D.
Nerdle, the mathematical marvel of a game! A delight for the brainy bunch who like to flex their mental muscles while having a jolly good time. This charming game involves solving a plethora of mathematical puzzles to guide our little Nerdle through a maze of obstacles. Nerdle Game is the perfect amalgamation of fun and learning, and will leave you feeling satisfied and smarter than ever before. So why not give it a go and see if you can conquer the mathematical marvel that is Nerdle!
I love this information you have written here. It’s insightful and interesting. I will come back for more as soon as I can. Thank you. 토토사이트추천
Thats Good For Who are Searching Something Else For Fun
What a great source of information. Such a wonderful collection of new ideas. I’ll definitely be back! 토토사이트
Thanks for this wonderful post! It has long been very helpful. I wish that you’ll carry on posting your wisdom with us. 토토사이트 I hope more and more people will find such a good article.
It’s a clever way to boost code adaptability and customization.
its me blippi Do you remember B L I P P I.
This guide has significantly improved my Bash scripting skills and I’m confident I can now use dynamic arrays effectively in my pokedoku projects.
The sheer size and selection of these web slots are mind-blowing. Great job. สล็อตเว็บใหญ่
It’s an amazing blog post, and it is really helpful as well.
Step into the world of Flores Santiago, where stunning floral arrangements mirror the unique blend of tradition and sophistication in Santiago. Our flowers are crafted to perfection, providing a touch of beauty and finesse to every celebration and sentiment. Explore Flores Santiago at its best, delivering floral masterpieces that echo the city’s charm in every bloom.
I’ve had bad experiences with slots breaking too easily. เว็บสล็อต
Your websites facilitate all the more each else volume is so engaging further serviceable It chooses me occur for withdraw reprise. I will in a split second snatch your rss channel to remain educated of any updates. รวมสล็อตทุกค่ายในเว็บเดียว
Here you will realize what is vital, it gives you a connection to an intriguing site page: เกมสล็อตโรม่า
I expounded on a comparable issue, I give you the connection to my site. เกมไพ่ป๊อกเด้ง
First, you should define your goals. What’s the snaptik purpose of your pokedoku webinar? Do you want to educate, promote a product, or engage your audience?
Thanks For Post
I am so lucky to finally find this article. I am a person who deals with kind of this too.토토사이트 This article has huge information for me, and well prepared for people who need about this. I am sure this must be comepletly useful for many people in the world.
Online casinos are a great way to bond with friends. Whether we’re competing against each other or trying out new games together, it always makes for a good time. 플러스카지노
ufa789 เข้าสู่ระบบ เว็บแทงบอลที่ใหญ่ และการเงินมั่นคงที่สุด สล็อตออนไลน์ ไม่มีขั้นต่ำ ใช้ทุนน้อย เล่นได้ทุกเกม
This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. Check this site: ufabet
This is a great approach for enhancing script efficiency and configurability!
For what reason do just such a great amount of composed regarding this matter? Here you see more. best concierge doctor
A debt of gratitude is in order for composing such a decent article, I staggered onto your blog and read a couple of post. I like your style of composing… รับจำนำรถ
Thanks for This Post
I think I have never observed such web journals ever that has finish things with all points of interest which I need. So sympathetically refresh this ever for us. รับจำนำรถ
Thanks For This Post
Well we extremely get a kick out of the chance to visit this site, numerous valuable data we can arrive. dispo travel spain
I am checking for and I have to post a remark that «The substance of your post is excellent» Great work! จำนำรถ
This Bash scripting technique offers valuable flexibility to figure out what is purple drywall. Choose the approach that best fits your version and coding style.
site! I truly love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I’ve subscribed to your RSS feed which must do the trick! Have a great day!betflik เว็บตรง
I admire the depth prostadine of research evident in this blog post.
The article’s content is commendable in its depth and merits significant recognition. I sincerely wish that your efforts garner substantial attention. Please visit the page LOLbeans io to have moments of fun and entertainment.
It’s a game. Five dollars is free. Try it It’s not an easy game
->-> 토토사이트.COM
The ambiance of a beauty salon is so inviting and comfortable. 池袋 通い放題エステ
Research the current market value of your iPhone model. Various online platforms, including auction sites, classified ads, and dedicated buyback programs, can give you an idea of how much you can expect to sell your device for. sell My iPhone
Are you tired of losing those captivating Instagram stories that you stumbled upon but couldn’t save? Worry no more! Introducing the Instagram Story Saver, your ultimate solution to effortlessly saving those ephemeral moments that vanish within 24 hours. storysaver.ws
I am overpowered by your post with such a decent theme. Typically I visit your web journals and get refreshed through the data you incorporate yet the present blog would be the most obvious. Well done! sumatra slim belly tonic
Individuals also turn to T-shirt printing to express their personal style or commemorate special occasions. Whether it’s designing a unique birthday gift or creating matching shirts for a group event, the possibilities are endless. Jacket printing singapore
Genuinely, this article is extremely one of the absolute best ever. I am an antique ‘Article’ gatherer and I at times read some new articles in the event that I discover them intriguing. What’s more, I discovered this one entirely captivating and it ought to go into my gathering. Good work! casa londra
Super site! I am Loving it!! Will return again, Im taking your sustenance moreover, Thanks. ceramiche sassuolo
Very excellent blog. Great job. asphalt sealcoating indianapolis
Unbelievable Blog! I should need to thank for the undertakings you have made in creating this post. I am believing a comparable best work from you later on moreover. I expected to thank you for this destinations! Thankful for sharing. Amazing destinations! ceramiche
Goodness! Such an astounding and supportive post this is. I outrageously cherish it. It’s so great thus amazing. I am simply flabbergasted. I trust that you keep on doing your work like this later on moreover. gres porcellanato effetto legno
Are you in need of Dihydrocodeine 30mg? You’ve come to the right place. Dihydrocodeine is a medication used to relieve moderate to severe pain. It belongs to a class of drugs known as opioid analgesics, which work by binding to opioid receptors in the brain and spinal cord, reducing the perception of pain. buy dihydrocodeine uk
Despite its effectiveness in managing pain, OxyContin carries a high risk of abuse and addiction. Like other opioids, OxyContin can produce feelings of euphoria and relaxation, which may lead some individuals to misuse or abuse the drug. Additionally, prolonged use of OxyContin can result in physical dependence, where the body becomes accustomed to the presence of the medication and experiences withdrawal symptoms when it is discontinued. oxycontin uk
Du kannst jetzt Caluanie Nuclear Oxidize online kaufen Sie können Caluanie Nuclear Oxidize jetzt online bei unserem besten Anbieter in DEUTSCHLAND kaufen. Unsere Mitarbeiter helfen Ihnen dabei, qualitativ hochwertige Caluanie Muelear Oxidate online zu den besten verfügbaren Preisen zu erhalten. Jetzt bestellen! muelear oxidize parteurize
It’s extremely pleasant and meanful. it’s extremely cool blog. Connecting is exceptionally valuable thing.you have truly helped bunches of individuals who visit blog and give them usefull data. aluminum welding wire types
I am awed by the data that you have on this blog. It demonstrates how well you comprehend this subject. Sliding mirror wardrobe
Thank you so much for your kind words and support! I’m truly honored to be a part of your learning journey and to assist you whenever you need guidance or have questions about new topics. Your enthusiasm for learning is inspiring, and I’m excited to continue exploring new subjects and expanding our knowledge together.
Remember, the best hairstyle for you depends on your hair type, face shape, and personal style preferences. Experiment with different looks to find the one that suits you best and makes you feel confident and comfortable.https://www.wpgio.com/15-trending-wavy-hairstyles-men/
Thank you so much for your kind words and support! I’m truly honored to be a part of your learning journey and to assist you whenever you need guidance or have questions about new topics. Your enthusiasm for learning is inspiring, and I’m excited to continue exploring new subjects and expanding our knowledge together.
Armed security guard services in New York offer an additional layer of protection for various industries and individuals requiring heightened security measures. Here are some key points to consider when seeking armed security guard services in New York NYC Security Guard