An example Analysis of the scope of variables in bash Loop
Editor to share with you the scope of variables in the bash cycle example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Let's take a look at a piece of wrong code first.
#! / bin/bash
For x in `ls * /. * /. * `
Cat $x | do echo $x
While read line
Do
C = `echo $line | awk-F' (''{print $1}'`)
# echo $c
ITunes $((iComplec))
Done
Echo
Done
Echo $I
What's wrong with the above code?
The pipe after cat will prevent the value of I from being incremented by 1.
The right way:
The code is as follows:
#! / bin/bash
For x in `ls * /. * /. * `
Do echo $x
While read line
Do
C = `echo $line | awk-F' (''{print $1}'`)
# echo $c
ITunes $((iComplec))
Done