Linux环境下的脚本—shell(二)
来源:互联网 发布:能写出这样的句子 知乎 编辑:程序博客网 时间:2024/06/06 04:32
一、变量
在其他编程语言中您必须使用变量。在shell编程中,所有的变量都由字符串组成,并且您不需要对变量进行声明。要赋值给一个变量,您可以这样写:
变量名=值
取出变量值可以加一个美元符号($)在变量前面;
变量赋值时,“=”两边都不能有空格
BASH中的语句结尾不需要分号;
例:HelloWorld
#!/bin/sh
#对变量赋值:
a="hello world"
# 现在打印变量a的内容:
echo "A is:"
echo $a
在编辑器中输入以上内容,然后将其保存为一个文件HelloWorld。之后执行chmod +x HelloWorld
最后输入./ HelloWorld执行该脚本。
这个脚本将会输出:
A is:
hello world
有时候变量名很容易和其他名字混淆,比如:
S13:
num=2
echo “this is the $numnd”
num=2
echo “this is the $numnd”
不会打印出“this is the 2nd”,而仅仅打印“this is the”,因为shell会去搜索numnd变量的值,但这个变量是没有值的。可以使用{}来告诉shell我们要打印的是num变量:
echo “this is the ${num}nd”
这将打印: “this is the 2nd”
0 0
- Linux环境下的脚本—shell(二)
- Linux环境下的脚本—shell
- Linux环境下的脚本—shell(三)
- Linux环境下的脚本—shell(四)
- Linux环境下的Shell使用进阶(二)
- Linux下eclipse中shell脚本编程环境的搭建
- Linux shell 脚本(二)
- linux下的shell脚本
- Linux下的SHELL脚本
- Linux Shell(二)——Shell的环境配置
- linux下shell脚本
- Linux——Shell管理脚本(二)
- 《Linux Shell脚本攻略》学习(二)
- Linux Shell脚本攻略(二)
- linux shell脚本攻略总结(二)
- Linux环境下c语言程序执行shell脚本
- Linux环境下通过shell脚本一键安装redis
- Linux下的shell脚本编程(一)
- opensuse安装genymotion
- 智慧北京:欢迎页面跳转
- 【UML】实现图
- BGD(Batch Gradient Descent), SGD (Stochastic Gradient Descent), MBGD (Mini-Batch Gradient Descent)
- 字符串替换。在原有字符串空间足够的情况下改变字符串中若干字符
- Linux环境下的脚本—shell(二)
- 流动布局的一个demo
- JAVA进阶6.5——线程的让步与阻塞
- 10.3 弱校 D Parentheses 思维题
- 【软考】IP地址的分类以及子网的划分
- 玩转矩阵的C小加
- cv2.imread(path)读取图片时,中文路径引起错误
- 聊一聊JQ中delegate事件委托的好处
- 开始博客的第一天