I have the following bash script:
files=[ls .]
for file in $files
do
digits=$(echo $file | sed "s/[^0-9]*\([0-9]\+\).*/\1/p")
if [[ $digits -gt 1000 ]]
then
rm $file
fi
done
Why am I getting:
11923: syntax error in expression (error token is "11923")
where 11923 is an example of one printed line when the $digits variable has value 11923?
EDIT:
I have found the error. The debuger says that the value of the $digits is duplicated (ex '1001 1001'). I am not sure why this is happening, though. The output of the debugger:
+ for file in *
++ echo image10961.jpg
++ sed 's/[^0-9]*\([0-9]\+\).*/\1/p'
+ digits='10961
10961'
+ [[ 10961
10961 -gt 1000 ]]
test.sh: line 5: [[: 10961
10961: syntax error in expression (error token is "10961")
$files? Is it a list of files? In any case you should be using an array, or more easily globing$filesvariable? Add the code please..