linux Shell 命令行-01-intro 入门介绍

拓展阅读

linux Shell 命令行-00-intro 入门介绍

linux Shell 命令行-02-var 变量

linux Shell 命令行-03-array 数组

linux Shell 命令行-04-operator 操作符

linux Shell 命令行-05-test 验证是否符合条件

linux Shell 命令行-06-flow control 流程控制

linux Shell 命令行-07-func 函数

linux Shell 命令行-08-file include 文件包含

linux Shell 命令行-09-redirect 重定向

shell

Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。

Shell 既是一种命令语言,又是一种程序设计语言。

Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。

Ken Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。

Shell 脚本

Shell 脚本(shell script),是一种为 shell 编写的脚本程序。

业界所说的 shell 通常都是指 shell 脚本,但读者朋友要知道,shell 和 shell script 是两个不同的概念。

由于习惯的原因,简洁起见,本文出现的 "shell编程" 都是指 shell 脚本编程,不是指开发 shell 自身。

Shell类型

  • Bourne Shell(/usr/bin/sh 或 /bin/sh)
  • Bourne Again Shell(/bin/bash)
  • C Shell(/usr/bin/csh)
  • K Shell(/usr/bin/ksh)
  • Root Shell(/sbin/sh)

通常,我们不区分 Bourne ShellBourne Again Shell

Shell 实战测试

创建 hello.sh

ruby 复制代码
houbinbindeMacBook-Pro:shell houbinbin$ pwd
/Users/houbinbin/code/shell
houbinbindeMacBook-Pro:shell houbinbin$ vi hello.sh

编辑 hello.sh 的内容

bash 复制代码
#!/bin/bash
echo "hello world!"

简单解释

hello.sh 的含义

#! 告诉操作系统要使用哪个解释器,echo 用于在窗口中打印信息。

运行

  • 运行 hello.sh
ruby 复制代码
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh hello.sh
hello world!
  • 另一种运行方式
ruby 复制代码
houbinbindeMacBook-Pro:shell houbinbin$ ./hello.sh
-bash: ./hello.sh: Permission denied
houbinbindeMacBook-Pro:shell houbinbin$ chmod +x ./hello.sh
houbinbindeMacBook-Pro:shell houbinbin$ ./hello.sh
hello world!

从输入读取

  • hello_name.sh
sh 复制代码
#!/bin/bash

# 作者:houbinbin

echo "请输入您的名字?"
read NAME
echo "您好,$NAME!"
  • 运行
ruby 复制代码
houbinbindeMacBook-Pro:shell houbinbin$ vi hello_name.sh
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh hello_name.sh
请输入您的名字?
houbinbin
您好,houbinbin!
houbinbindeMacBook-Pro:shell houbinbin$

参考资料

www.runoob.com/linux/linux...

Shell 中文教程
Shell 中文教程 本文由博客一文多发平台 OpenWrite 发布!

相关推荐
丿BAIKAL巛21 小时前
Java前后端传参与接收全解析
java·开发语言
cc蒲公英21 小时前
javascript有哪些内置对象
java·前端·javascript
guslegend21 小时前
Spring AOP高级应用与源码剖析
java
Rover.x21 小时前
head table is mandatory
java·apache
yanghuashuiyue21 小时前
Java过滤器-拦截器-AOP-Controller
java·开发语言
shoubepatien21 小时前
JAVA —— 03
java·jvm
a努力。21 小时前
【基础数据篇】数据等价裁判:Comparer模式
java·后端
小冷coding21 小时前
【Java】高并发架构设计:1000 QPS服务器配置与压测实战
java·服务器·开发语言
哈哈哈笑什么21 小时前
SpringBoot 企业级接口加密【通用、可配置、解耦的组件】「开闭原则+模板方法+拦截器/中间件模式」
java·后端·安全
期待のcode21 小时前
springboot依赖管理机制
java·spring boot·后端