Hi all,
I have the code as below "
echo "File carried list after 1st loop "${fileStreamAssiagnInit[@]}""
and I have the out put for the above code as below :
Output : File carried list after 1st loop abcInd.csv sdgUS.csv sopSing.csv
Here i want to count the number of elements in the array
I tried ${#fileStreamAssiagnInit[@]} but it doesn't work.I need the output as 3 but it gives me zero.
Here one more Help required
fileStreamLoad=""ab.csv","bc.csv","cd.csv","de.csv","ef.csv","fg.csv"";
fileStreamAssign=($fileStreamLoad);
echo "File carried list after 1st loop "${fileStreamAssiagnInit[@]}"" // its being carried from some other result.
If [ $count -eq 2 ]
then
fileStreamAssign="${fileStreamAssiagnInit[@]}" // I am not able to assign the array values to another array which is already having the values.
fi
for ((i=0,j=0; i<${#fileStreamAssign[@]}; ++i));
do
if [ -f ${fileStreamAssign[$i]} ]
then
cp ${fileStreamAssign[$i]} $destPath/${fileStreamAssign[$i]}_$(date +%Y%m%d)
else
fileStreamAssiagnInit[$j]="${fileStreamAssign[$i]}"
j=$(($j+1))
fi
done
If you could help that would be great thanks
Hello,
For counting the number of elements in an array as per your exampple. Please try the following. Kindly let me know in case you have queries.
$ cat array_count.ksh
fileStreamLoad=""ab.csv","bc.csv","cd.csv","de.csv","ef.csv","fg.csv"";
j=0
value_fileStreamLoad=`echo $fileStreamLoad | sed 's/,/ /g; s/\"//g'`
set -A array_fileStreamLoad ${value_fileStreamLoad}
echo ${array_fileStreamLoad[@]}
for a in ${array_fileStreamLoad[@]}
do
let "j = j +1"
done
echo $j
Output for this script is as follows.
$ ksh array_count.ksh
ab.csv bc.csv cd.csv de.csv ef.csv fg.csv
6
$
Note: You can comment the bold line in comment if you don't want to show array's elements.
Thanks,
R. Singh
fileStreamLoad=""ab.csv","bc.csv","cd.csv","de.csv","ef.csv","fg.csv"";
fileStreamAssign=($fileStreamLoad);
set count=2
echo "File carried list after 1st loop "${fileStreamAssiagnInit[@]}"" //Output : File carried list after 1st loop abcInd.csv sdgUS.csv sopSing.csv
for a in ${fileStreamAssiagnInit[@]}
do
let "p = p +1"
done
echo $p
if [ $countfun -eq 2 ]
then
for ((k=0; k<$p; ++k));
do
fileStreamAssign="${fileStreamAssiagnInit[$k]}"
done
echo "File carried list fileStreamAssign "${fileStreamAssiagn[@]}"" //Output required : File carried list fileStreamAssign abcInd.csv sdgUS.csv sopSing.csv
fi
Could you help me to assign the array value to another array ?
You realize you can't quote quotes, right?
You realize shell doesn't have //-style comments, right?
Your entire program is severely confused. What, exactly, is your goal here? And don't say 'assign an array to another array', tell me why you're assigning an array to another array... I suspect you're severely confused, there are probably much, much more direct ways to do what you want.