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?
Thanks, Lou ######## # Appends the configuration data for each picture in the images.xml file OLDIFS="$IFS" IFS=$'\n' #******** 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 done IFS="$OLDIFS" ######## # adds final data to xml file: cat xml-post-cart >> $XMLHOME/$NAME |
I think you are talking about "sourcing" a file.
In a script, if you include: Quote:
|
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. Code:
cat >>$XMLHOME/$NAME << -EOF 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. |
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, Lou |
All times are GMT -5. The time now is 12:28 AM. |