ubuntu下shell脚本编写:命令封装
一、命令封装
1、新建.sh脚本文件
2、编辑文件
#!/bin/bash #申明shell脚本,固定
echo -e "install open5gs start!\n" #打印输出
sudo apt update
sudo apt install mongodb
sudo systemctl start mongodb
sudo systemctl enable mongodb
sudo ip tuntap add name ogstun mode tun
sudo ip addr add 10.45.0.1/16 dev ogstun
sudo ip addr add 2001:230:cafe::1/48 dev ogstun
sudo ip link set ogstun up
sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libnghttp2-dev libmicrohttpd-dev libcurl4-gnutls-dev libnghttp2-dev meson
proxychains4 git clone https://github.com/open5gs/open5gs
iperf -u -c 10.128.226.205 -i 1 -t 5 -b 100M
read -p "are you sure delete open5gs? Y/N: " choose #读键盘输入
if ["$choose"=="Y"]; then
sudo rm -rf open5gs
fi #结束if
read -p "Restart now? Y/N: " st
if ["$st"=="Y"]; then
sudo reboot now
fi
3、给文件赋权
chmod 文件名 a+x #a为所有用户 x为可执行文件
4、运行
sudo ./脚本
二、输入输出
#!/bin/bash
read -p "firstname: " firstname
read -p "lastname: " lastname
echo -e "\nyourname is : $firstname $lastname"