I want my script to define an empty array. array values should be added if predefined condition gets true. for this what i have done is
declare -a FILES
file_count=0
if [ "$file_ext" != "$SUPPORTED_FILE_TYPE" ] ; then
echo "$file_ext is not supported for this task."
else
$FILES[$file_count] = $filename
file_count=$file_count+1
fi
when executing this script i am getting some error like this
linux-softwares/launchers/join_files.sh: 51: [0]: not found
you can write it this way as well
To: Vijay
tiny demonstration, list *.txt files in directory and put to array FILES
output
When settings data in array does not recall with $:
FILES without $.
This works for me:
As you see, a little modification $(( )) for math operation, but the FILES assignements is the same...
As pointed out after lots of tests, Ubuntu default shell seems to be dash, which raised the error.
To add an element to the end of an array, use the += operator (since bash 3.1 in 2004):