I'm completely new in the Linux world, i-m using a Bash shell and practicing a bit. How can i perform a loop giving as counter an expression? For example looping through the amount of word in a file.
for n in(wc -w text.txt)
do
echo "word number $n"
done
Unfortunately the above script its not working. The only way i have found so far is to first print the value of wc -w text.txt, then assign it to a variable and then loop:
wc -w text.txt
a=10 //result saw by wc -w text.txt
for((b=0; b<a; b++))
do
echo "$b"
done
The problem is that i need to retrieve the value of wc -c and asssing it directly to a variable, in case i have to write a script that runs automatically, the problem is that
a= wc -w test.txt
Will not work,
Any advice?
a=wc -w test.txtshould be in backticks or$()to work and no space around=, i.e.a=$(wc -w test.txt)a=$(wc -w < test.txt)to remove the filename inwcoutput.