473,732 Members | 2,227 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 2996
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
24083
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
5557
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
4862
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
3209
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
6502
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
2207
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
21609
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
2163
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
2234
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
8946
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9235
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,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
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
6031
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.