PowerShell for循环笔记 230325

PowerShell for循环笔记 230325

创建hello0到hello9九个文件

内容和文件名一样,
可以这么写
在这里插入图片描述

for($i=0;$i-lt10;$i++){echo hello$i > hello$i}

for($i=0;$i-lt10;$i++) 可以完全没有空格 , 连$i-lt10( -lt是小于的意思 )之间都可以没有空格

PS H:\zmp\23\230325> for($i=0;$i-lt10;$i++){echo hello$i > hello$i}
PS H:\zmp\23\230325> ls


    目录: H:\zmp\23\230325


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2023/3/25     21:30             18 hello0
-a----         2023/3/25     21:30             18 hello1
-a----         2023/3/25     21:30             18 hello2
-a----         2023/3/25     21:30             18 hello3
-a----         2023/3/25     21:30             18 hello4
-a----         2023/3/25     21:30             18 hello5
-a----         2023/3/25     21:30             18 hello6
-a----         2023/3/25     21:30             18 hello7
-a----         2023/3/25     21:30             18 hello8
-a----         2023/3/25     21:30             18 hello9

也可以有空格

  • for($i=0;$i-lt10;$i++)
  • for($i=0;$i -lt 10;$i++)
  • for($i=0; $i -lt 10; $i++)
  • for ( $i=0; $i -lt 10; $i++ )
  • for ( $i=0 ; $i -lt 10 ; $i++ )

hello尾接 可以用 hello$i 拼接字符串

helloXworld 就不能用 hello$i了 , 要用大括号 hello${i}world 或 hello"$i"world

for ( $i=0 ; $i -lt 10 ; $i++ ){ echo hello${i}world > hello${i}world.txt }
for ( $i=0 ; $i -lt 10 ; $i++ ){ echo hello"$i"world > hello"$i"world.txt }
PS H:\zmp\23\230325> rm *
PS H:\zmp\23\230325> ls
PS H:\zmp\23\230325> for ( $i=0 ; $i -lt 10 ; $i++ ){ echo hello${i}world > hello${i}world.txt }
PS H:\zmp\23\230325> ls


    目录: H:\zmp\23\230325


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2023/3/25     21:52             28 hello0world.txt
-a----         2023/3/25     21:52             28 hello1world.txt
-a----         2023/3/25     21:52             28 hello2world.txt
-a----         2023/3/25     21:52             28 hello3world.txt
-a----         2023/3/25     21:52             28 hello4world.txt
-a----         2023/3/25     21:52             28 hello5world.txt
-a----         2023/3/25     21:52             28 hello6world.txt
-a----         2023/3/25     21:52             28 hello7world.txt
-a----         2023/3/25     21:52             28 hello8world.txt
-a----         2023/3/25     21:52             28 hello9world.txt


PS H:\zmp\23\230325> rm *
PS H:\zmp\23\230325> ls
PS H:\zmp\23\230325> for ( $i=0 ; $i -lt 10 ; $i++ ){ echo hello"$i"world > hello"$i"world.txt }
PS H:\zmp\23\230325> ls


    目录: H:\zmp\23\230325


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2023/3/25     21:53             28 hello0world.txt
-a----         2023/3/25     21:53             28 hello1world.txt
-a----         2023/3/25     21:53             28 hello2world.txt
-a----         2023/3/25     21:53             28 hello3world.txt
-a----         2023/3/25     21:53             28 hello4world.txt
-a----         2023/3/25     21:53             28 hello5world.txt
-a----         2023/3/25     21:53             28 hello6world.txt
-a----         2023/3/25     21:53             28 hello7world.txt
-a----         2023/3/25     21:53             28 hello8world.txt
-a----         2023/3/25     21:53             28 hello9world.txt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kfepiza

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值