[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Setting Multiple Shell Variables from One Run of awk



Mumia W.. wrote:
On 09/30/2008 01:48 PM, Martin McCormick wrote:


<--deleted problem description and awk solution-->


The bash shell can do this internally since it supports arrays:

NEWDEV=${NEWDEV//./ }
NEWDEV=($NEWDEV)
echo "hostname: ${NEWDEV[0]}"
echo "domain: ${NEWDEV[1]}"
echo "top0: ${NEWDEV[2]}"
echo "top1: ${NEWDEV[3]}"

Of course you're free to assign the array elements to variables if you desire. See "man bash" for more about arrays.


This is certainly true. There's almost always another way to solve a problem.

The only issue I would have with this solution is that it's specific to modern shells, such as bash and ksh. If you want something that will also work with older, less feature full shells, you may not be able to use such advanced features.

Otherwise, a nice solution, as it avoids the extra process for awk.

--
Bob McGowan

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: