shell教程 (脚本执行)

shell是一个用c语言编写的程序,它是用户使用linux的桥梁。既是一种命令语言,又是一种程序设计语言。
shell是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。
ken thompson 的sh 是第一种Unix Shell ,Windows Explorer 是一个典型的图形界面shell。

Shell脚本

shell脚本(shell script) ,是一种为shell编写的脚本程序。
业界所说的shell通常都是指shell脚本,但是shell和shell script 是俩个不同的概念。本文出现的“shell编程”都是指shell脚本编程,不是指开发shell本身。

Shell 环境

shell 编程跟JavaScript 、php编程一样,只要有一个能编写代码的文本编辑器和一个能解释执行的脚本解释器就可以了。

第一个shell脚本

vim创建一个文件,扩展名可以sh 也可以是py 也可以是txt,不影响

[root@localhost ~]# vim calculator.sh 
#!/bin/bash
echo "hello World !"

~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
~                                                            
"test.sh" 3L, 34C    

#!是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行。就是用哪种shell

运行Shell脚本有俩种方法:

1.作为可执行程序

保存文件,赋权限,运行

[root@localhost ~]# chmod +x calculator.sh 
[root@localhost ~]# ll 
总用量 8
drwxr-xr-x. 2 root root  6 11月  6 14:36 111
lrwxrwxrwx. 1 root root  3 11月  6 14:37 222 -> 111
-rwx--x--x. 2 root root 35 11月  6 10:42 aaa
lrwxrwxrwx. 1 root root 13 11月  6 14:38 bbb.sh -> calculator.sh
-rwx--x--x. 2 root root 35 11月  6 10:42 calculator.sh
[root@localhost ~]# ./calculator.sh 
hello world !
[root@localhost ~]# 
2、作为解释器参数

这种运行方式是,直接运行解释器,其参数就是 shell 脚本的文件名,如:

[root@localhost ~]# /bin/sh test.sh
hello World !
[root@localhost ~]# /bin/php test.php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值