[root@localhost ~]# echo -e "SHELL\nPython\nGOlang"
SHELL
Python
GOlang
[root@localhost ~]# echo -e "Linux\tWindows\tUNIX"
Linux Windows UNIX
[root@localhost ~]# echo "hello!!"
echo "hellocat /etc/hosts"
hellocat /etc/hosts
[root@localhost ~]# echo 'hello!!'
hello!!
[root@localhost ~]# cat << eof
> 1. 创建虚拟机
> 2. 查看虚拟机
> 3. 销毁虚拟机
> 4. 查看系统资源
> eof
[root@localhost ~]# vim 1.sh
cat << eof
1、创建虚拟机
2、查看虚拟机
3、删除虚拟机
4、恢复虚拟机
5、回到上一步
eof
[root@localhost ~]# bash 1.sh
1、创建虚拟机
2、查看虚拟机
3、删除虚拟机
4、恢复虚拟机
5、回到上一步
输出重定向
> >> 2> &>
输入重定向
<
[root@localhost ~]# ls -ldh /etc/ > /tmp/file01
[root@localhost ~]# cat /tmp/file01
drwxr-xr-x. 76 root root 8.0K Sep 17 09:02 /etc/
[root@localhost ~]# ls -ldh /dev/ > /tmp/file01
[root@localhost ~]# cat /tmp/file01
drwxr-xr-x 20 root root 3.2K Sep 17 09:02 /dev/
[root@localhost ~]# ls -ldh /dev/ > /tmp/file01
[root@localhost ~]# cat /tmp/file01
drwxr-xr-x 20 root root 3.2K Sep 17 09:02 /dev/
[root@localhost ~]#
[root@localhost ~]# ls -ldh /etc/ >> /tmp/file01
[root@localhost ~]#
[root@localhost ~]# cat /tmp/file01
drwxr-xr-x 20 root root 3.2K Sep 17 09:02 /dev/
drwxr-xr-x. 76 root root 8.0K Sep 17 09:02 /etc/
[root@localhost ~]# ls -ldh /etc/ > /dev/null
[root@localhost ~]# ls -ldh /dsjlfdsjlfdsjlf 2> /dev/null
[root@localhost ~]# ls -ldh /etc/ 2> /dev/null
drwxr-xr-x. 76 root root 8.0K Sep 17 09:02 /etc/
[root@localhost ~]# tr 'a-z' 'A-Z' < /tmp/file01
ABCDE
变量名称=值
[root@localhost ~]# ip_address=192.168.152.10
[root@localhost ~]# echo $ip_address
192.168.152.10
[root@localhost ~]# echo $(ip_address)
[root@localhost ~]# data=server
[root@localhost ~]# echo "There are some $datas"
There are some
[root@localhost ~]# echo "There are some ${data}s"
There are some servers
[root@localhost ~]# read -p "用户名: " name
用户名: userA
[root@localhost ~]# echo $name
userA
[root@localhost ~]# vim 1.sh
read -p "用户名:" user
echo "您好:" $user
[root@localhost ~]# bash 1.sh
用户名:lijianhua
您好: lijianhua
[root@localhost ~]# a=10
[root@localhost ~]# b=20
[root@localhost ~]# c=a+b
[root@localhost ~]#
[root@localhost ~]# echo $c
a+b
[root@localhost ~]# c=$a+$b
[root@localhost ~]# echo $c
10+20
[root@localhost ~]# a=10
[root@localhost ~]# b=20
[root@localhost ~]# echo $((a+b))
30
[root@localhost ~]# let c=a+b
[root@localhost ~]# echo $c
30
[root@localhost ~]# declare -i c=a+b
[root@localhost ~]# echo $c
30
[root@localhost ~]# let rand=$RANDOM%100
[root@localhost ~]# echo $rand
43
env
临时生效:export 环境变量=值
永久生效:vim /etc/profile
export 环境变量=值
示例一:定义历史命令的时间
export HISTTIMEFORMAT="%F_%T "
示例二:定义当前用户历史命令行数,默认1000
export HISTSIZE=10
示例三:修改系统语言
export LANG=en_us.UTF-8
#!/bin/bash
#
mkdir /mnt/cdrom
sed -i '$a \/dev/sr0 /mnt/cdrom iso9660 defaults 0 0' /etc/fstab
mount -a
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/CentOS* /etc/yum.repos.d/backup/
touch /etc/yum.repos.d/yum.repo
cat << eof > /etc/yum.repos.d/yum.repo
[centos]
name=centos
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
eof
yum repolist
#!/bin/bash
#
read -p "手动配置IP地址,请输入:" ip
nmcli connection modify ens160 autoconnect yes ipv4.method manual ipv4.addresses $ip ipv4.gateway 192.168.152.2 ipv4.dns 223.5.5.5
nmcli connection reload
nmcli connection up ens160 >> /dev/null
IP=$(ifconfig ens160 | sed -n '2p' | awk '{print $2}')
ROUTE=$(route -n | sed -n '3p' | awk '{print $2}')
DNS=$(cat /etc/resolv.conf|sed -n '2p' | awk '{print $2}')
echo "=============================="
echo -e "更改后的IP:$IP\n更改后的网关为:$ROUTE\n更改后的DNS为:$DNS"
223.5.5.5
nmcli connection reload
nmcli connection up ens160 >> /dev/null
IP=$(ifconfig ens160 | sed -n ‘2p’ | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') ROUTE=(route -n | sed -n ‘3p’ | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') DNS=(cat /etc/resolv.conf|sed -n ‘2p’ | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') echo "======…IP\n更改后的网关为:KaTeX parse error: Undefined control sequence: \n at position 6: ROUTE\̲n̲更改后的DNS为:DNS"