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.
sorry for not using correct terms, but the example i've provided is very similar to final script.
what i want is a script with few variables at the beggining (what i call configuration block) that will be edited by operators, and then the main code of the script. some of the variables of the configuration block can include variables that are used later.
i dont want operators mess with the code, just configure somethings. this is a little elaborated example:
Code:
#!/bin/bash
# configuration block
FLOG="$DIRLOG/register-in.log"
#############################################
## please dont touch nothing from this point
#############################################
DIRLOG="/usr/local/appregister/logs"
tail -f "$FLOG"
i dont want operators mess with the code, just configure somethings.
That makes sense.
The tidiest solution would be to use an external file for the configuration data. Most simply this can be sourced into the master script. It's easier to illustrate than describe. Here's the config file, let's call it /etc/local/my.conf:
This has the advantage that the script is not changed to configure anything which makes support a lot easier, including knowing which version is in use.
#!/bin/bash
# configuration block
FLOG="<dirlog>/register-in.log"
#############################################
## please dont touch nothing from this point
#############################################
DIRLOG="/usr/local/appregister/logs"
FLOG=`echo "$FLOG" | sed "s|<dirlog>|$DIRLOG|"`
tail -f "$FLOG"
Well personally I cannot see how that is more maintainable, but good to see you found a solution.
There are many possible solutions to the requirement with various pros and cons, each of which has more or less weight depending on context; it is hard to imagine a context in which the chosen solution is optimal.
For configuration, IMO catkin's solution of sourcing a config file is the most elegant way to go about it, and the method I use whenever I need something like that. eval is bad here, you need to be doing something *really* special to justify all the headaches it brings.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.