I’m trying to do the following:
CPU_COUNT=$(cat /proc/stat | grep -E "^cpu[[:digit:]]+ " | wc -l)
let CPU_COUNT=CPU_COUNT-1
for core in {0..$CPU_COUNT}; do
echo $core
done
On a system with 4 cores, I would expect the bash script to loop 4 times, incrementing core from 0 to 3.
The output I receive is however:
{0..3}
What I’m doing is clearly wrong, but how do I make it work as intended?
You are looking for
seq.Edit: You can use getconf(1) to get the number of CPU available: