tranicus
asked on
Problem with arrays on cygwin.
Hello all,
this is an attempt to setup an arrays in cygwin on Windows shell scripts:
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
i=0
for field2 in `cat dir_s.txt | awk '{print $4}'`
do
if [ "$field2" != bytes ]
then
echo "${field1[$i]} $field2" >> join_file.txt
else
i=i+1
fi
done
I kept getting an error:
for field2 in `cat dir_s.txt | awk '{print $4}'`
do
if [ "$field2" != bytes ]
then
echo "${field1[$i]} $field2" >> join_file.txt
test.sh: 35: Syntax error: Bad substitution
this is an attempt to setup an arrays in cygwin on Windows shell scripts:
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
i=0
for field2 in `cat dir_s.txt | awk '{print $4}'`
do
if [ "$field2" != bytes ]
then
echo "${field1[$i]} $field2" >> join_file.txt
else
i=i+1
fi
done
I kept getting an error:
for field2 in `cat dir_s.txt | awk '{print $4}'`
do
if [ "$field2" != bytes ]
then
echo "${field1[$i]} $field2" >> join_file.txt
test.sh: 35: Syntax error: Bad substitution
ASKER
the log indicated "cat dir_dir.txt | awk '{print $3}'" it does return data. it seem the array having problem of storing data.
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field[*]} > join_file.txt
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field[*]} > join_file.txt
Did you try the alternate syntax that I showed you?
Also, in that example you just barely posted, you have a typo. Try one of the following:
field1=( `cat dir_dir.txt | awk '{print $3}'` )
echo ${field1[*]}
and
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field1[*]}
Do you get output in either case?
Also, in that example you just barely posted, you have a typo. Try one of the following:
field1=( `cat dir_dir.txt | awk '{print $3}'` )
echo ${field1[*]}
and
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field1[*]}
Do you get output in either case?
ASKER
This work:
set field1=`cat dir_dir.txt | awk '{print $3}'`
echo $field1
but once I placed arrays to it.
field1=`cat dir_dir.txt | awk '{print $3}'` ###minor modification to work in my env.
echo ${field1[*]}
error: echo ${field1[*]}
test.sh: 14: Syntax error: Bad substitution
same error for the next statement.
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field1[*]}
I am beginning to think this version of Cygwin cannot do arrays. The syntax are basic.
set field1=`cat dir_dir.txt | awk '{print $3}'`
echo $field1
but once I placed arrays to it.
field1=`cat dir_dir.txt | awk '{print $3}'` ###minor modification to work in my env.
echo ${field1[*]}
error: echo ${field1[*]}
test.sh: 14: Syntax error: Bad substitution
same error for the next statement.
set -a field1 `cat dir_dir.txt | awk '{print $3}'`
echo ${field1[*]}
I am beginning to think this version of Cygwin cannot do arrays. The syntax are basic.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
nope, it didn't work. I am going to download a new version of cygwin and try it with that.
value=( `ls` )
echo ${value[*]}
value=( `ls` )
echo ${value[*]}
ASKER
I just downloaded the latest cygwin. Yup, its the old version I had that did not support arrays. Tested your command and it work:
value=( `ls` )
echo ${value[*]}.
thank you for your help.
value=( `ls` )
echo ${value[*]}.
thank you for your help.
Great! Glad it's working.
field1=( `cat dir_dir.txt | awk '{print $3}'` )
If you try that and it still doesn't work, I would make sure that the command:
cat dir_dir.txt | awk '{print $3}'
is actually returning output.