首页 > 系统相关 >linux Shell 命令行-01-intro 入门介绍

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

时间:2024-03-10 12:22:33浏览次数:32  
标签:shell 01 sh Shell linux houbinbin intro hello

拓展阅读

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

houbinbindeMacBook-Pro:shell houbinbin$ pwd
/Users/houbinbin/code/shell
houbinbindeMacBook-Pro:shell houbinbin$ vi hello.sh

编辑 hello.sh 的内容

#!/bin/bash
echo "hello world!"

简单解释

hello.sh 的含义

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

运行

  • 运行 hello.sh
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh hello.sh
hello world!
  • 另一种运行方式
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
#!/bin/bash

# 作者:houbinbin

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

参考资料

https://www.runoob.com/linux/linux-shell.html

Shell 中文教程

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

标签:shell,01,sh,Shell,linux,houbinbin,intro,hello
From: https://www.cnblogs.com/houbbBlogs/p/18063981

相关文章

  • 通达信中波01号指标公式源码副图
    {通达信中波01号指标公式源码副图}X_1:=(MA(AMOUNT,5)/MA(vol,5)/100-MA(AMOUNT,125)/MA(VOL,125)/100)/(MA(AMOUNT,5)/MA(VOL,5)/100);X_2:=MA((LLV(LOW,28)-CLOSE)/(HHV(HIGH,28)-LLV(LOW,28))*100,5);X_3:=IF(NAMELIKE(1),0,1)ANDIF(NAMELIKE(2),0,1);X_4:=(CLOSE-MA(......
  • day01 markdown学习
    markdown学习有一个官方学习教程网站:https://markdown.com.cn文本编辑器typora或者在线markdown编辑markdown是一个轻量级标记语言,文件后缀名.md或者.markdown看下面教程的时候打开源代码模式1.标题有六个标题模式1.#+空格+文字一级标题2.##+空格+文字二级标题3.###+......
  • L1-019 谁先倒
    第一次没AC,对题目有点误解。我以为如果酒量是1,喝一杯就会倒下,实际上应该喝两杯才倒下,修改了判断条件,就过了。#include<bits/stdc++.h>usingnamespacestd;intmain(){ intat,bt,n,a1,a2,b1,b2,x1=0,x2=0;//x1是甲喝的酒x2是乙喝的酒 cin>>at>>bt>>n; for(inti......
  • apache2.4在windows server2012上出现内存溢出解决方法
    今天把服务器迁移到windowsserver2012发现出现web请求不稳定,内存飙升,经常发生卡顿现象,找了很多原因,最后找到了关键因素。在apache的配置文件httd.conf下注释掉:EnableMMAPoffEnableSendfileOffAcceptFilterhttpnoneAcceptFilterhttpsnone这样就搞定了! 现......
  • [NOIP2017 提高组] 小凯的疑惑 / [蓝桥杯 2013 省] 买不到的数目
    这肯定是学证明了,看这篇文章补充一下细节首先,\(m\)的范围应该是\([0,b-1]\)然后,当\(m\)取不同值的时候,\(ma\)%\(b\)一定为不同值(这个性质确实有点奇特,可以记下来)反证,如果\(m_1a\equivm_2a\:(mod\:b)\)且\(0≤m_1<m_2≤b-1\),那么就有\(b|(m_2-m_1)a\),题目给出了\(a,b\)互质,......
  • [蓝桥杯 2019 省 B] 后缀表达式
    这题没想到怎么贪心,看题解恍然大明白#include<iostream>#include<stdio.h>#include<algorithm>#include<string>#defineFor(i,j,n)for(inti=j;i<=n;++i)usingnamespacestd;typedeflonglongLL;constintN=2e5+5;LLans;in......
  • [蓝桥杯 2019 省 B] 等差数列
    实际上这道题不需要先排序再求gcd,因为无论是哪两项之前作差,都不会影响最后的gcd的结果。因为公差是从a2-a1开始算的,因此i=1时要特殊处理,不能把a1-0计入贡献,否则会算出错误的gcd。即作差时不要加上a1-0,统计最值时不要漏掉a1#include<iostream>#include<stdio.h>#include<a......
  • 下载Office 2016 PC版 办公软件
    Office2016专业增强版是微软公司推出的一款办公软件套装,专为满足中小型企业和个人用户的多样化需求而设计。它包含了以下应用程序:Word:用于创建和编辑文档Excel:用于创建和编辑电子表格PowerPoint:用于创建和编辑演示文稿Outlook:用于管理电子邮件、日历和联系人Publisher:用......
  • Rust-入门-01
    Rust语言有哪些特性?建议一:从整体出发,不要让自己陷入到细节中去建议二:抛弃一次性学会的念头语言架构所有权系统编程范式语言架构类型系统内存管理Rust语言设计哲学是什么?Rust社区和生态如何?参考1......
  • 中考英语首字母快速突破001-2021上海宝山英语二模
    PDF格式公众号回复关键字:ZKSZM001原文Whatislaughter?Laughterisnaturalforpeople.Westarttolaughataboutfourmonthsofage.Westarttolaughevenbeforewestarttospeak!Laughterissocial.Itconnectsuswithotherpeople.Welaughmorewhenw......