473,699 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do PHP "require()" or TCL "source" in bash script

I'm sorry but I can't figure out how to explain this any better than
this.

In PHP we have a command "require()" that obtains a file and logically
places it into another file.

I cannot figure out how to do this in bash script as the requirement
is necessary for a migration script to obtain the code from a .cfg
file and then be able for the "parent" script to run the code it
"imported" from the .cfg file, much like PHP's require() or TCL's
"source".

This is what I have so far and it fails:

if [ -f ivc.cfg ]; then
cat ivc.cfg
fi

Anyone really know bash script well please help, it's a barrier for me
not to be able to get just this one piece working.

Thanx
Phil
Jul 17 '05 #1
5 2989
In comp.os.linux.m isc Phil Powell <so*****@erols. com> wrote:
In PHP we have a command "require()" that obtains a file and logically
places it into another file.


Isn't the same as the $include ?

Davide

--
| Zero Defects, n.: The result of shutting down a production line.
|
|
|
Jul 17 '05 #2
On 9 Jul 2004 20:32:14 GMT, Davide Bianchi
<da************ @onlyforfun.net > wrote:
In comp.os.linux.m isc Phil Powell <so*****@erols. com> wrote:
In PHP we have a command "require()" that obtains a file and logically
places it into another file.


Isn't the same as the $include ?


Almost.

require() does the same thing include() does with the difference being
if include() fails the script can still continue. If require() fails,
the script must end.

There's also include_once() and require_once() with the same
capabilities as their non _once'd countrparts and the nicly added
feature of not reloading the same require or include more than once.
--
gburnore@databa six dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺ ݳ޳ݳݳ޳ݳ ۳
| ۳ݳ޳ݳۺ ݳ޳ݳݳ޳ݳ ۳
DataBasix | ۳ݳ޳ݳۺ ݳ޳ݳݳ޳ݳ ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
=============== =============== =============== =============== ===============
Want one? GET one! http://signup.databasix.com
=============== =============== =============== =============== ===============
Jul 17 '05 #3
["Followup-To:" header set to comp.os.linux.m isc.]
On 2004-07-09, Phil Powell wrote:
I'm sorry but I can't figure out how to explain this any better than
this.

In PHP we have a command "require()" that obtains a file and logically
places it into another file.

I cannot figure out how to do this in bash script as the requirement
is necessary for a migration script to obtain the code from a .cfg
file and then be able for the "parent" script to run the code it
"imported" from the .cfg file, much like PHP's require() or TCL's
"source".
What's wrong with bash's "source" command?

[ -f ivc.cfg ] && source ivc.cfg

Or is that not what you want?
This is what I have so far and it fails:

if [ -f ivc.cfg ]; then
cat ivc.cfg
fi
What do you mean, "fail"? Your snippet will do exactly what it is
written to do: send the contents of ivc.cfg to stdout.
Anyone really know bash script well please help, it's a barrier for me
not to be able to get just this one piece working.


The source command will only work if the contents of the cg file
are a valid shell script, e.g., "variable=value ". Otherwise, you
will have to parse the file:

[ -f ivc.cfg ] && while read -r line
do
: parse each line here; code depends on format of the line
done < ivc.cfg

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
=============== =============== =============== =============== =======
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Jul 17 '05 #4
In comp.os.linux.m isc, Phil Powell uttered these immortal words:
In PHP we have a command "require()" that obtains a file and logically
places it into another file.

I cannot figure out how to do this in bash script as the requirement
is necessary for a migration script to obtain the code from a .cfg
file and then be able for the "parent" script to run the code it
"imported" from the .cfg file, much like PHP's require() or TCL's
"source".

This is what I have so far and it fails:

if [ -f ivc.cfg ]; then
cat ivc.cfg
fi


I'm no bash script expert but I get by. I would say that that's along the
right lines. This works for me:

[ -f ivc.cfg ] || exit 1
.. ivc.cfg

If the file's not there the script exits with a value of 1 otherwise it
reads and executes ivc.cfg.

Then there's:

if [ -f ivc.cfg ]
then
. ivc.cfg
else
echo "Required file not found."
exit 1
fi

If the file's not there the script prints a message and exits with a value
of 1 otherwise it reads and executes ivc.cfg.

--
Andy.
Jul 17 '05 #5
In comp.os.linux.m isc Gary L. Burnore <gb******@datab asix.com> wrote:
Isn't the same as the $include ?

Almost.
require() does the same thing include() does with the difference being


No, no. I was talking about the $include in a bash script. Not in PHP.

Davide

--
| Everybody wants to go to heaven, but nobody wants to die.
|
|
|
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
24074
by: Matt Kruse | last post by:
This is a common requirement - "freeze panes" in a table, so that some header rows and some columns on the left are frozen while the body content scrolls. This makes large tables more usable on screen. There are a number of solutions available. For example, http://www.litotes.demon.co.uk/example_scripts/tableScroll.html I'm just wondering if anyone knows of a "latest and greatest" script to solve this problem. My requirement at the...
4
5549
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. When the user clicks to start the download I would like to display the "Save As" dialog, allow the user to name a place to save the file, and then show the download progress bar while the file downloads Question: How do I make a windows "Save...
31
4858
by: Yeah | last post by:
Is it absolutely necessary to include "http://" in an A HREF hyperlink? Would it be wise to remove this from one's Links page, just to save code?
5
3206
by: Jim Carlock | last post by:
I've set up the following using an Alias in Apache... Alias /phpdocs/ "C:/Apache/htdocs/common/docs/php/" <Directory "C:/Apache/htdocs/common/docs/php"> Options Indexes FollowSymlinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
1
6493
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
5
2206
by: lister | last post by:
Hi all, I have a fairly diverse range of data that I want to cache in the session rather than pulling it from the database on every page refresh. The problem is is that it seems that PHP requires the class definitions available on EVERY page, as it unserialises everything even if it's not going to be used.
8
21604
by: Steve Kershaw | last post by:
I have a debugging/breakpoint problem that I must fix before I move on!!! When I set a breakpoint in my ASP.NET (C#) page I get the red circle with the 'A'. When I mouse over this breakpoint I get one of two errors: First error "The breakpoint will not currently be hit. No symbols have been loaded for this document"
2
2155
by: sabbadin12 | last post by:
Hi, I'm going to work on an application that uses a postgreSQL database so that it can uses SQLServer 2005. I think I solved most problems on the programming side, but I still have some doubts on the DB side regarding how to handle the creation of the db schema on sqlserver and how to handle the every day dba work. 1) should I try to use an ER tool like Embarcadero and have its logical model be the master copy ? (i did some tests, it...
19
2227
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? (in conjunction with css, you know, the usual...;) this is what is meant by "modern" javascript?? so how do folks feel about this who think javascript is so evil they disable it from their browsers?? do sites designed with "modern" javascript...
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9034
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.