美文网首页
Bash脚本

Bash脚本

作者: Oooyzx | 来源:发表于2019-08-10 14:21 被阅读0次

Shell_01_认识Bash
https://www.jianshu.com/p/02ad4dbd9161
Shell_02_变量
https://www.jianshu.com/p/6cbb93ff9d4e
Shell_03_文件描述符
https://www.jianshu.com/p/db5a19fb582a

认识 Bash

shell保存于 /etc/shell中

image.png

Bash的功能

  • 1.命令别名: alias, unalias:
image.png
1.1 取消grep的--color 用 \ 转义:
\grep 转义

=======================================================

2.stty 隐藏输入
image.png
2.1 从键盘输入并用cat显示出来
image.png
2.2 将键盘输入的内容输出到inputinfo里面:
image.png
2.3 将家目录下的.bashrc的文件输入到inputinfo里:
image.png

=====================================================

bash 的登录主机欢迎信息: /etc/issue, /etc/motd

image.png
image.png

cut补充

image.png

变量

image.png
![image.png](https://upload-images.jianshu
.io/upload_images/125327-587ed7b0fdd4a7bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

[root@oyzx]vim .bashrc


image.png

[root@oyzx]. .bashrc
[root@oyzx]echo $username
oyzx

=====================================================

image.png
image.png
  • 替换和取代:


    image.png

作业

写个脚本,执行后输出如下结果:

目前的登录用户数:
w |head -1 | cut -d "," -f 2
服务器名称:
hostname
服务器的物理 CPU 颗数
grep 'physical id' /proc/cpuinfo | sort -u | wc -l
1
服务器每颗物理 CPU 的核心数是
grep 'cpu cores' /proc/cpuinfo | uniq
cpu cores : 1

内存总容量
cat /proc/meminfo|head -1 |cut -d ":" -f 2
999696 kB

硬盘总容量
fdisk -l |grep Disk|head -1|cut -d "," -f 1
Disk /dev/sda: 21.5 GB

相关文章

  • Bash基础知识

    在上一篇文章《不过时的技术-Bash脚本》中,我们简单介绍了Bash脚本,并且学会如何编写、运行一个Bash脚本。...

  • 12)Shell 编程

    脚本格式要求 1.脚本以 #!/bin/bash 开头 (表示用 bash 来进行解析) 2.脚本需要有可...

  • 基础Bash Shell脚本编程

    在bash脚本的第一行要写上#!/bin/bash来告诉系统该脚本是bash脚本这一行在Linux中被称为sheb...

  • 第1节 shell脚本创建执行和输出

    #shell脚本创建执行和输出 1.shell脚本开头 #!/bin/bash /bin/bash 是Ba...

  • shell脚本简单的基本语法

    1.脚本的格式要求 1.脚本以#!/usr/bash开头,表示编写的脚本以bash这种终端解释器来解析。 2.脚本...

  • bash脚本编程

    bash脚本之编程交互 脚本参数 用户交互,通过键盘输入数据,从而完成变量的赋值操作 bash -n 脚本 检查...

  • 入门:脚本

    总结 脚本就是给机器一行一行执行的文本 Bash 脚本有Bash 脚本的语法,Node.js 脚本有 JS 语法 ...

  • bash脚本

    所以说,脚本就是给计算机照着做的。这是我们对「脚本」的一个感性认识。接下来我们写一个脚本。 写一个脚本 找个地方新...

  • Bash脚本

    Shell_01_认识Bashhttps://www.jianshu.com/p/02ad4dbd9161Shel...

  • bash脚本

    介绍: Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,...

网友评论

      本文标题:Bash脚本

      本文链接:https://www.haomeiwen.com/subject/orqhdctx.html