一、Shell脚本入门

什么是Shell

Shell是一个命令解释器,它的作用是解释执行用户输入的命令及程序等。

常见操作系统默认Shell

  • bash(Linux下默认)
  • sh(Solaris和FreeBSD默认)
  • ksh(AIX默认)

查看系统默认Shell命令

[root@tz ~]# echo $SHELL
/bin/bash
[root@tz ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash

设置vi别名

[root@tz yum.repos.d]# echo "alias vi='vim'" >>/etc/profile
[root@tz yum.repos.d]# tail -1 /etc/profile
alias vi='vim'
[root@tz yum.repos.d]# source /etc/profile

脚本开头

脚本第一行指出由哪个解释器程序执行脚本内容,其他行#开头都为注释

#!/bin/bash

查看系统版本

[root@tz yum.repos.d]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

查看Shell版本

[root@tz yum.repos.d]# bash --version
GNU bash, 版本 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.

查看bash软件是否有破壳漏洞

[root@tz yum.repos.d]# env x='() { :;}; echo be careful' bash -c "echo this is a test"
this is a test

除以上情况需要升级bash

[root@tz yum.repos.d]# yum -y update bash
[root@tz yum.repos.d]# rpm -qa bash
bash-4.2.46-31.el7.x86_64

猜你喜欢

转载自www.cnblogs.com/tz90/p/12631973.html