liunx SHELL脚本

来源:百度知道 编辑:UC知道 时间:2024/06/17 10:07:45
麻烦各位高手教我SHELL脚本的基本使用方法

Shell脚本基本知识

概述:shell其实是内核与用户之间的一个接口,

shell脚本

如果有一系列经常使用的linux命令,你可以把它们存储在一个文件肿。shenll可以读取这个文件,并执行其中的命令。这样的文件成为脚本文件。

执行shell脚本

要创建一个shell脚本,你要使用任何编辑器比如vi在文本文件中编写他。

为了使用bash shell赖执行脚本magic,其命令是:bash magic或者./magic

echo命令:

echo “this is an example of the echo command!”

屏幕上就会回显“this is an example of the echo command!”

#符号

用于在shell脚本肿可以包含注解入口

echo “hello”

#this is a comment line. this would not produce any output!

echo “world!”

第二行是一个注解的例子。它将被shell忽略,而且不产生任何消息

变量:

可以在任何时间通过简单的赋值来创建。

语法:

<variable name>-<value>

Linux 中的所有变量都被当作字符串

引用变量:

$符号用于引用一个变量的内容

variable1 = ${variable2}

读入值给变量

在执行sh