0

The script works fine as it should, it shows the folders contained on a given path, but I am trying to add a counter to know how many there are but it won't work I've tryed many things, googled etc but can't get it right What's the problem? Sorry for the Spanish

the code

https://i.sstatic.net/y6ogf.jpg

it prints this

https://i.sstatic.net/BTvl0.jpg

1
  • 1
    Please paste the actual code in your questions rather than screenshots. It's much easier to handle and actually searchable. Commented May 15, 2015 at 4:30

3 Answers 3

1

You must use "let" in front of your variable reassignment in the loop.

let $contador = $contador + 1
Sign up to request clarification or add additional context in comments.

1 Comment

works just the same way with the let :/, thanks though
1

try let but this way

let contador = $contador + 1

example:

[~]=> c=100; for i in {0..45}; do let c=$c+1; done; echo $c
146

On the side note, your whole script looks to do this :

find . -type d -mindepth 1 -maxdepth 1 -print | wc -l

any particular reason you don't use find?

Comments

0

You can't do variable assignment with the dollar symbol on the left side. That is, you should do:

var=...

Not

$var=...

And, in addition to using 'let' you can increment your variable like this

var=$(( var + 1 ))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.