The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
double substitution pppswing Shell Programming and Scripting 1 07-03-2008 09:10 AM
Bash: bad substitution problem...pls help! xfouxs UNIX for Dummies Questions & Answers 1 11-23-2007 05:48 PM
how to read double consecutive space in filename for bash shell james_falco UNIX for Dummies Questions & Answers 1 07-17-2007 05:32 PM
Double Substitution variables in ksh xiamin Shell Programming and Scripting 19 05-23-2007 05:35 AM
double variable substitution asal_email2 UNIX for Dummies Questions & Answers 1 06-14-2005 01:35 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-09-2009
flee flee is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
How do I perform double substitution in bash?

#!/bin/bash
#set -x
MAX=255
FILE=$1.dns_list
#declare -a d_arr

if [ -z "$1" ]
then
echo "Usage: `basename $0` network"
echo " e.g.`basename $0` 1.1.1"
exit
fi

echo "Remove file $FILE..."
rm $FILE

for (( i = 1; i < $MAX; i++ ))
do
PARSE=$(host $1.${i})
if [ $? = 0 ]
then
echo "$PARSE" " $1.$i" >> $FILE
fi
done

cat $FILE | while read i
do
declare -a d_arr
ln=`echo $i | awk '{printf $5 "\t : \t" $6}' |sed 's/\.XYZ\.com\.//g'`
cnt=${#d_arr[@]}
let c=$cnt
d_arr[$c]=$ln # <<---<< I think I need double substitution for this stmt
echo ${d_arr[$c]}
done

# For some reason the array does not exist
cnt1=${#d_arr[@]}
echo "The size of d_arr: $cnt1"
echo "The array ${d_arr[@]}"
exit

Hi,

How do I perform double substitution in bash?

I try to write a bash script to list all the DNS entry from a subnet e.g. 192.168.1.0/24 and store the valid DNS entry into an array ${d_arr[]},
The variable d_arr[$c] works fine in while read i loop, but once the loop finished, array ${d_arr[]} is empty, I have tried he following:

let ${d_arr[$c]}=$ln

but get a syntax error.

How do I get it store into an array for the duration when he program is still running?

Thanks,
-Fu
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0