Manage parameter-file

Hi @ll

what is the best way to manage a parameter-file?I have a file like this:

par1=value1par2=value2 #commentpar3=value3

i have a menu and there is a menu-point which is called "set par1", when i choice this point comes a prompt where i can give the value for par1. after i give the value, how can i set this value in the parameter-file? and also read from the file?

Re: Manage parameter-file

Thanks @ll

is there also a chance to do this:# perl -i.old -ple 's/par2\s*=.+\b/par2=newvalue/' parmsfilein ksh or awk? nice solution with perl, but i wouldn't mix a lot of programming languages, if possible only ksh and awk.

Re: Manage parameter-file

Hi Oviwan:

Perl's regular expression handling is one of the best available. Since perl allows updating in-place, whereas 'awk' or 'sed' force you to redirect modified output into a second file and then rotate that second file over the first, I also choose perl for this task.

As far as mixing various languages, then, one sees this all the time in shell scripts. Consider the number of shell lines with 'sed' and 'awk' snippets. If a shell uses 'cut' or 'grep' in reality that too is mixing languages since the later are C-code.

Could your requirement be met wholly in shell? Well, yes. For instance, you could parse your parameter file by using the shell's IFS (inter-field-separator) much along the lines of what I did with 'split' in the 'awk' code.

Re: Manage parameter-file

You asked, "...what is more professional? to mix a lot of languages or only use of one or two (if possible)? how do you handle this at your own?"

I prefer to drive screws with screwdrivers and nails with hammers. By this I mean, I perfer to do things easily and gracefully with the tools that offer both ease of use and good performance.

Just because you can do something in language X doesn't mean that you should. I want readable, maintainable (flexible) code that performs well using a minimum of server resources in that order. Sometimes mixing two languages (e.g. shell + awk or shell + sed or shell + perl) is an easy solution. The whole Unix philosophy is built around the idea of plumbing and to me this is one case of it.

Certainly as one becomes more familar and proficient with a language, like any tool, one tends to grab it at the start of a project. Many of the tasks we do in shell scripts could be re-written in perl. In cases where a working piece of code already exists I find no harm in leveraging another language for a small subtask.

"Mixing" languages is really nothing more than calling modules or libraries and that generally means making things easier in my opinion.