473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Include files in shell script.

I have one configuration file. It will be used by perl and shell script. From perl using 'require' I have included the configuration file. Using require, include statement I tried in shell script , but it was not working.
How to include a file and read value from that file using shell script?
May 10 '10 #1
3 22312
Using 'source' we can acheive teh including of files in shell script.

Example:

filename: config
var=260

filename: a.sh
Expand|Select|Wrap|Line Numbers
  1. source config
  2. echo $var
  3.  
when we run the a.sh file, we can get the 'var' value as, 250..
May 10 '10 #2
numberwhun
3,509 Expert Mod 2GB
Your probably wondering why I moved your posting. You mentioned in it that you are trying to do the same in Perl and shell scripting, but that the shell scripting is what is not working.

Because that makes this a shell scripting question, I have moved it to the Unix forums to get an answer. Next time, please select the best appropriate forum based on the contents of your questioin.

Now, your question.....

Including the file in the script using the source or '.' commands (which do the same thing) is one way. If you wanted to actually read the file, line by line, you could also do something like this:

Expand|Select|Wrap|Line Numbers
  1. while read line
  2. do
  3.   echo $line
  4. done < infile
  5.  
Hope that helps!
May 10 '10 #3
Hi! Just in case you still need that function in shell script, I had made a project just for the solution. Here's the link:

Shell Script Loader
Google Search

With it you can have something like this:
Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2.  
  3. # load the helper script
  4. . ./loader.sh
  5.  
  6. # include other scripts
  7. include script1.sh
  8. include script2.sh
  9.  
  10. ....
The files script1.sh and script2.sh will only be loaded once and can also be specified in other scripts.

If you need an example project that already uses it you may get an example package from PlayShell.
Sep 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Tom Cat | last post by:
Is there anything wrong with using a lot of include files? On one part of my website, I have a form. The page it posts data to, includes a different file based on some of the values. The...
4
by: Tom Bates | last post by:
Possible? It seems nobody knows how... :-) Tom
2
by: jonathan184 | last post by:
Hi I am trying to create a shell script that will look for a contracthead file first and if the contract head file does not exist on day1 exit script. Now on day2 if contracthead exists or...
9
by: niteck07 | last post by:
I am using following shell script to ftp files to another server but this is failing as the shell script changes the user name for the ftp login the correct user name is 'ag\invprint' which the...
1
by: newfresher | last post by:
Hi, I want to write a shell script which ll access the folder, open it and read the series of text/sql files their one after another, in it. After reading one text/sql file, commands their in...
6
by: lawrence k | last post by:
Suppose I have a PHP script that I call at the Linux command line (Ubuntu), and it gets all the paths to files and directories that exist inside of some directory. All this data gets stored in an...
1
by: jrw133 | last post by:
So im working on a lab for my unix class and im having some problems with this shell script we are supposed to do here is the question: Write a shell script that accepts a list of files(space...
16
by: pereges | last post by:
Do you see anything wrong about this method ? For eg. I write a shell script a.sh containing : cc -o test file1.c file2.c file3.c and then execute the shell script ( sh a.sh) to compile and...
1
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.