> -----Original Message----- > From: Linux on 390 Port [mailto:[email protected]] On > Behalf Of Bauer, Bobby (NIH/CIT) [E] > Sent: Thursday, December 23, 2010 10:29 AM > To: [email protected] > Subject: A little more script help > > OK, I'm going to forgo Rexx and learn bash script! > I want to input a file into an array. For instance I want the > variable xyz to have the contents of /tmp/test. /tmp/test looks like: > > 08:50:01 AM all 3.48 0.00 0.18 0.15 > 0.19 95.99 > 09:00:02 AM all 3.51 0.00 0.19 0.15 > 0.11 96.05 > > > I tried: > > xyz=(`cat /tmp/test`) > and > xyz=('grep all /tmp/test`) > > but I only get the first word, the 08:50:01. How can I get > everything? > > Thanks > Bobby Bauer
A good place to start reading, IMO, http://tldp.org/LDP/abs/html http://tldp.org/LDP/abs/html/arrays.html <quote> Example 27-5. Loading the contents of a script into an array #!/bin/bash # script-array.sh: Loads this script into an array. # Inspired by an e-mail from Chris Martin (thanks!). script_contents=( $(cat "$0") ) # Stores contents of this script ($0) #+ in an array. for element in $(seq 0 $((${#script_conten...@]} - 1))) do # ${#script_conten...@]} #+ gives number of elements in the array. # # Question: # Why is seq 0 necessary? # Try changing it to seq 1. echo -n "${script_contents[$element]}" # List each field of this script on a single line. # echo -n "${script_contents[element]}" also works because of ${ ... }. echo -n " -- " # Use " -- " as a field separator. done echo exit 0 # Exercise: # -------- # Modify this script so it lists itself #+ in its original format, #+ complete with whitespace, line breaks, etc. </quote> -- John McKown Systems Engineer IV IT Administrative Services Group HealthMarkets(r) 9151 Boulevard 26 * N. Richland Hills * TX 76010 (817) 255-3225 phone * [email protected] * www.HealthMarkets.com Confidentiality Notice: This e-mail message may contain confidential or proprietary information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. HealthMarkets(r) is the brand name for products underwritten and issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life Insurance Company of TennesseeSM and The MEGA Life and Health Insurance Company.SM ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 ---------------------------------------------------------------------- For more information on Linux on System z, visit http://wiki.linuxvm.org/
