没有合适的资源?快使用搜索试试~ 我知道了~
linuxSHELL学习之for、while、until
需积分: 9 2 下载量 185 浏览量
2014-12-21
16:00:58
上传
评论
收藏 6KB TXT 举报
温馨提示
试读
10页
linuxSHELL学习之for、while、until
资源推荐
资源详情
资源评论
linuxSHELL学习之for、while、until
一、for命令用于循环操作
1、读取列表中的复杂值
*使用转义字符(反斜杠符号)来转义单引号
*使用双引号来定义使用单引号的值
[root@t1 ~]# cat t20.sh
#!/bin/bash
for test in I don't know if this'll work
do
echo "word:$test"
done
[root@t1 ~]# ./t20.sh
word:I
word:dont know if thisll ---不是我们想要的结果
word:work
[root@t1 ~]# cat t21.sh
#!/bin/bash
for test in I don\'t know if "this'll" work --使用 "\"转义单引号,使用双引号定义使用单引号的值
do
echo "word:$test"
done
[root@t1 ~]# ./t21.sh
word:I
word:don't
word:know
word:if
word:this'll
一、for命令用于循环操作
1、读取列表中的复杂值
*使用转义字符(反斜杠符号)来转义单引号
*使用双引号来定义使用单引号的值
[root@t1 ~]# cat t20.sh
#!/bin/bash
for test in I don't know if this'll work
do
echo "word:$test"
done
[root@t1 ~]# ./t20.sh
word:I
word:dont know if thisll ---不是我们想要的结果
word:work
[root@t1 ~]# cat t21.sh
#!/bin/bash
for test in I don\'t know if "this'll" work --使用 "\"转义单引号,使用双引号定义使用单引号的值
do
echo "word:$test"
done
[root@t1 ~]# ./t21.sh
word:I
word:don't
word:know
word:if
word:this'll
word:work
2、运行多字值,for循环认为每个值都用空格分开,如果有包含空格的数据值,就会遇到另一个问题:又包含空格的值就必须用双引号引起来使用。
[root@t1 ~]# cat t22.sh
#!/bin/bash
for test in New Hampshire New York New Mexico
do
echo "Now going to $test"
done
[root@t1 ~]# ./t22.sh ---不是想要的结果
Now going to New
Now going to Hampshire
Now going to New
Now going to York
Now going to New
Now going to Mexico
[root@t1 ~]# cat t23.sh
#!/bin/bash
for test in "New Hampshire" "New York" "New Mexico" ---使用双引号之后得到想要的结果
do
echo "Now going to $test"
done
[root@t1 ~]# ./t23.sh
Now going to New Hampshire
Now going to New York
Now going to New Mexico
3、从变量读取列表
[root@t1 ~]# cat t24.sh
#!/bin/bash
2、运行多字值,for循环认为每个值都用空格分开,如果有包含空格的数据值,就会遇到另一个问题:又包含空格的值就必须用双引号引起来使用。
[root@t1 ~]# cat t22.sh
#!/bin/bash
for test in New Hampshire New York New Mexico
do
echo "Now going to $test"
done
[root@t1 ~]# ./t22.sh ---不是想要的结果
Now going to New
Now going to Hampshire
Now going to New
Now going to York
Now going to New
Now going to Mexico
[root@t1 ~]# cat t23.sh
#!/bin/bash
for test in "New Hampshire" "New York" "New Mexico" ---使用双引号之后得到想要的结果
do
echo "Now going to $test"
done
[root@t1 ~]# ./t23.sh
Now going to New Hampshire
Now going to New York
Now going to New Mexico
3、从变量读取列表
[root@t1 ~]# cat t24.sh
#!/bin/bash
剩余9页未读,继续阅读
资源评论
Thor丶果冻
- 粉丝: 32
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功