How to pass an argument to a variable that has been assigned a script?
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.
please tell us what is your goal, what do you want to achieve (how should it work?)
i recently found out that we can run certain commands by assigning them to a variable, for example :
$ abc=`ls |wc -l` will return total no. of files when we do :
$ echo $abc
so tried to assign a whole script to the variable 'a' as posted. this script will accept command line arguments like 'jan' or 'feb' or any name of a month when running via a editor like 'vi'. So i tried to pass arguments to the variable as i would have done when running the script normally. Is there a way to do so?? I hope you understand my point now...!!!
there is a way to do that, but this is not the usual way (I mean assign a script to a variable is quite unusual).
you may try eval $variable to achieve something like that, but it is not really recommended and possibly unsafe.
there is a way to do that, but this is not the usual way (I mean assign a script to a variable is quite unusual).
you may try eval $variable to achieve something like that, but it is not really recommended and possibly unsafe.
@abhiJ: You mention in your first post that you created a script, but if I look at this "script" it seems that this is not the case, it is a function run from the shell.
You also mention this:
Quote:
this script will accept command line arguments like 'jan' or 'feb' or any name of a month when running via a editor like 'vi'
How does vi come into the picture?
It seems that you are trying to do something the hard way and your posts do not make clear what it is you want/need to do.
Am I right in assuming that you want to extract some information from a database, based on the input given (jan, feb, ...) and store all the output generated in a variable?
If so; What is this variable going to be used for?
i am just trying to find out if there is a way to pass an argument (which is used to retrieve certain data from a script) to a variable that has been assigned a script???
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.