Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the scope of variables in bash Loop

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report