Supressing an error message in bash script
Neil Cherry
ncherry at linuxha.com
Sat Dec 12 03:43:00 UTC 2009
On 12/11/2009 10:23 PM, Ray Parrish wrote:
> Neil Cherry wrote:
>> On 12/11/2009 09:40 PM, Ray Parrish wrote:
>>
>>> function ArrayLoad {
>>> PackageData=`"dpkg -p gedit"` 2> /dev/null
>>>
>>
>> Try it without the double quotes. Does that do what you want?
>>
> Wirhout the double quotes nothing gets loaded into the array.. Also
> nothing gets loaded into the array with my original code, as the output
> thst I thought ewas being generated by that function, was actually being
> output by the following function which works very nicely. I had
> forgotten to comment out it's call in my test code so it was generating
> the loop output before the only output of the first function I quoted
> which was the error message.
>
> # Test array assignment from variable line by line
> function ReadintoArray {
> PackageData=`dpkg -p gedit`
> LoopCount=0
> while read ThisLine; do
> Data[$LoopCount]="$ThisLine"
> echo "$LoopCount - ${Data[$LoopCount]}"
> (( LoopCount++ ))
> done <<<"$PackageData"
> }
>
> I guess I'll go with this second version which works great, unless
> someone can tell me how to load the array with a single call like I was
> trying in the other function. Just looking for the most efficient way to
> get the data into the array line by line.
After I sent the message I notice a number of problems. I'm not
familiar with arrays and without the quotes there's no array.
Sorry
--
Linux Home Automation Neil Cherry ncherry at linuxha.com
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
More information about the ubuntu-users
mailing list