Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Search this Thread
Old 06-06-2008, 12:05 AM   #1
LQ Newbie
Registered: Jul 2006
Posts: 14

Rep: Reputation: 0
script to call commands from another file

Hello. I am looking for a way to have my script run the commands seen below within the #******** separators from a separate file, rather from within the script itself. Can anyone tell me how to accomplish that?


# Appends the configuration data for each picture in the images.xml file
for i in `cat $IN`;do
echo "Creating configuration data for $i"
WC=`wc -l out`
printf ' <product>\n' /r >> $XMLHOME/$NAME
printf ' <itemNumber>'$WC'</itemNumber>\n' /r >> $XMLHOME/$NAME
printf ' <name>Shopping Cart Cover</name>\n' /r >> $XMLHOME/$NAME
printf ' <price>59.99</price>\n' /r >> $XMLHOME/$NAME
printf ' <description>'$i'</description>\n' /r >> $XMLHOME/$NAME
printf ' <pic>'$SM'/'$i'.jpg</pic>\n' /r >> $XMLHOME/$NAME
printf ' <picture>'$BM'/'$i'.jpg</picture>\n' /r >> $XMLHOME/$NAME
printf ' <size>No Options</size>\n' /r >> $XMLHOME/$NAME
printf ' <color>No Shipping Options,</color>\n' /r >> $XMLHOME/$NAME
printf ' </product>\n' /r >> $XMLHOME/$NAME
# printf ' ' \n' /r >> $XMLHOME/$NAME
echo >> $XMLHOME/$NAME

echo "line" >> out
# adds final data to xml file:
cat xml-post-cart >> $XMLHOME/$NAME
Old 06-06-2008, 12:20 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
I think you are talking about "sourcing" a file.

In a script, if you include:
. filename
then that file is made part of your script.
Old 06-06-2008, 12:57 AM   #3
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The IFS variable is for input not for output.

Most of your script seems to be creating a file that is embedded in the script. Your script doesn't seem to be calling another script however. Look at "here" documents in the bash info manual. (section 3.6.5) That is how embedded scripts & files are usually written. The scripts can contain variables which are expanded, depending on how the terminator is written after the << characters.

cat >>$XMLHOME/$NAME << -EOF
          <name>Shopping Cart Cover</name>
          <size>No Options</size>
          <color>No Shipping Options,</color>
Your code could perhaps construct an xml file in parts. First cat'ing a file (>) that contains your standard header. Second adding a <product>..</product> entry for each product entry you need (>>), and finally adding the last line(s) which may contain a closing tags if any from the first header part.

This is how a lot of software was distributed in the past. An installation script would contain a number of embedded files which were created when the script was run.

Last edited by jschiwal; 06-06-2008 at 12:59 AM. Reason: typo: 3.5.5 -> 3.6.5
Old 06-06-2008, 08:15 AM   #4
LQ Newbie
Registered: Jul 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the helpful information. I wrote one of these scripts to create an XML file for each product that a flash shopping cart uses. The end-user simply runs the script (via web) after adding new pictures of their products to the appropriate directory. From there the script processes the info and makes the XML output.

In the end I needed the pricing and option data to be in one file that would be called by all of the individual product scripts so that the end-user would only need to update one file when a price or option change was made (all the products are the same price and use the same options).

The ". file" was exactly what I needed, and I will test creating the XML using the above more-appropriate format.

Many thanks,


bash, xml

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
How do I call a .sh script from a kickstart file? below_average Linux - Software 2 01-17-2008 09:46 AM
How can I script an autologin, automatically call kde(or simillar) and call an app aboaventura Slackware 8 02-03-2007 11:00 PM
HTTP call to CGI Script no file association meligon Linux - General 12 12-02-2006 11:55 AM
two commands in a script file not working toastermaker Programming 6 01-04-2004 07:15 AM

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration