[SOLVED] Passing variables to a program in a bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Trying to do a simple bash script, and having some issues. I am relatively new to bash, and did my best to search, but idk what exactly to search for.
Doesn't work:
Code:
DIALOG="1 test"
dialog --menu "Choose OS for install:" 10 30 1 ${DIALOG}
Works:
Code:
dialog --menu "Choose OS for install:" 10 30 1 1 test
Just trying to figure out how to tell it it's two different arguments and not one. I'm sure this is an issue with escaping, but I'm not sure how to fix it.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Well some more information would be nice, like when you are executing the lines above, are they all being done at the prompt or from a script?
This worked fine for me (at prompt):
Code:
$ x="10 30 1 1 test"
$ dialog --menu "Choose OS for install:" $x
ok, I figured out what the problem was (1 of them anyway). I was using IFS to read a variable (newlines and stuff), and I never unset it after, so that solved one problem.
Here is my second problem (instead of making a new thread, cause it goes along with the title anyway).
Code:
#!/bin/bash
DIALOG="1 \"test with spaces rawr\""
dialog --menu "Choose OS for install:" 10 70 1 $DIALOG
It's not seeing the quotes when I do that, so it's reading it as 5 arguments and not 2. (1, "test, with, spaces, rawr") not (1, "test with spaces rawr")
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.