how to access variables in a config file inside a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to access variables in a config file inside a shell script
# 8  
Old 06-16-2009
no need that many tools. use just awk
Code:
set -- $(awk -F"=" '$1=="a"{ram=$2}
$1=="b"{shaym=$2}
$1=="c"{hari=$2}
END{
 print ram,shaym,hari
}' file)
echo $1
echo $2
echo $3

with bash
Code:
while IFS="=" read -r a b
do
 case $a in
 "a") ram=$b;;
 "b") shyam=$b;;
 "c") hari=$b;;
 esac
done < file
echo $ram,$shyam,$hari

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Update config file using shell script in Solaris 5.10

hi I need to update the value in config.txt value using shell script example: lets say a value in config.txt file is as SEQUENCE=1 after some iteration as the loop ends , the SEQUENCE should get update in the config.txt file with a new value of SEQUENCE=2. also , can anyone please help me... (7 Replies)
Discussion started by: ravidwivedi2288
7 Replies

5. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

6. Shell Programming and Scripting

How to access outparameter of a Procedure called inside a shell script?

Hi I am calling a PLSQL procedure inside a shell scipt. How to access out paramters of this procedure inside the mail shell script. I am using below peiece of code. echo " inside PKG validation" `sqlplus -s login/password@database <<EOF set heading off set... (6 Replies)
Discussion started by: karnatis
6 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. Shell Programming and Scripting

Edit a config file using shell script

I need to edit a config file using shell script. i.e., Search with the 'key' string and edit the 'value'. For eg: below is what I have in the config file "configfile.cfg". Key1=OldValue1 Key2=OldValue2 I want to search for "Key1" and change "OldValue1" to "NewValue1" Thanks for your... (7 Replies)
Discussion started by: rajeshomallur
7 Replies

9. Shell Programming and Scripting

How to parse config variables from external file to shell script

How do i use a config.txt to recursively pass a set of variables to a shell script eg my config.txt looks like this : path=c://dataset/set1 v1= a.bin v2= b.bin path=c://dataset/set2 v1= xy.bin v2= abc.bin .................. and so on . and my testscript : (2 Replies)
Discussion started by: pradsh
2 Replies

10. Shell Programming and Scripting

How to access the C program variables in shell script

hi I wanted to access the C program variables in shell script. This script is called from the same C program. What are the ways in which i can access variables thankx (3 Replies)
Discussion started by: bhakti
3 Replies
Login or Register to Ask a Question
CGI::Application::Plugin::Config::Simple(3pm)		User Contributed Perl Documentation	     CGI::Application::Plugin::Config::Simple(3pm)

NAME
CGI::Application::Plugin::Config::Simple - Add Config::Simple support to CGI::Application SYNOPSIS
in your CGI::Application based module use CGI::Application::Plugin::Config::Simple; sub cgiapp_init { my $self = shift; #set my config file $self->config_file('myapp.conf'); # #do other stuff # } #later on in a run mode sub run_mode1 { my $self = shift; #just get a single parameter from my config file my $value = $self->config_param('my_param'); #get a parameter in a block (if using ini style files) $value = $self->config_param('my_block.my_param'); #the entire config hash reference my $config_vars = $self->config_param(); #get my Config::Simple object for direct access my $config = $self->config; } DESCRIPTION
This module acts as a plugin for Config::Simple to be easily used inside of a CGI::Application module. It does not provide every method available from Config::Simple but rather easy access to your configuration variables. It does however provide direct access to the underlying Config::General object created if you want to use it's full power. The module tries to make the getting and setting of configuration variables as easy as possible. Only three methods are exported into your CGI::Application module and they are described below. Before I wrote this module sometimes I would put my code that read in the configuration file into the cgiapp_init() or cgiapp_prerun() methods but then if I had a run mode that didn't need those config variables it was run anyway. This module helps to solve this is. The Config::Simple object is not created (and the config file is not read and parsed) until after your first call to config() or config_param() to either retrieve/set values, or get the Config::Simple object. This lazy loading idea came from Cees Hek's CGI::Application::Plugin::Session module. METHODS
config_param() This method acts as an accessor/mutator for configuration variables coming from the configuration file. This method will behave in three different ways depending on how many parameters it is passed. If 0 parameters are passed then the entire config structure will be returned as a hash ref. If 1 parameters is passed then the value of that parameter in the config file will be returned. If more than 1 parameter is passed then it will treat them as name value pairs and will set the parameters in the config file accordingly. In this case, if we successfully set the parameters then a true value will be returned. #get the complete config hash my $config_hash = $self->config_param(); #just get one config value my $value = $self->config_param($parameter); #set multiple config values my $success = $self->config_param(param1 => $value1, param2 => $value2); This method uses Config::Simple so if you are using ini-files then you can set the values of variables inside blocks as well using the '.' notation. See Config::Simple; You must set the name of the configuration file either using the config_file() method or the CGIAPP_CONFIG_FILE environment variable before calling this method or it will 'die'. config() This method will return the underlying Config::Simple object for more direct use by your application. You must set the name of the configuration file either using the config_file() method or the CGIAPP_CONFIG_FILE environment variable before calling this method or it will 'die'. my $conf = $self->config(); config_file([$file_name]) This method acts as an accessor/mutator to either get the name of the current config file or to change/initialize it. This method must be called to initialize the name of the config file before any call can be made to either config() or config_param() unless the 'CGIAPP_CONFIG_FILE' environment variable has been set. If this environment variable is set it will be used as the initial value of the config file. This is useful if we are running in a mod_perl environment when can use a statement like this in your httpd.conf file: PerlSetEnv CGIAPP_CONFIG_FILE /path/to/my/conf It is typical to set the name of the config file in the cgiapp_init() phase of your application. If a value is passed as a parameter then the config file with that name is used. It will always return the name of the current config file. #get the value of the CGIAPP_CONFIG_FILE environment variable (if there is one) #since we haven't set the config file's name with config_file() yet. my $file_name = $self->config_file(); #set the config file's name $self->config_file('myapp.conf'); #get the name of the config file $file_name = $self->config_file(); CAVEATS
The CGI::Application object is implemented as a hash and we store the variables used by this module's methods inside of it as a hash named __CONFIG_SIMPLE. If you use any other CGI::Application plugins there would be problems if they also used $self->{__CONFIG_SIMPLE} but in practice this should never actually happen. AUTHOR
Michael Peters <mpeters@plusthree.com> Thanks to Plus Three, LP (http://www.plusthree.com) for sponsoring my work on this module SEE ALSO
o CGI::Application o Config::Simple LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-11-10 CGI::Application::Plugin::Config::Simple(3pm)