ubuntu下shell脚本编写:命令封装

本文介绍了如何在Ubuntu系统中编写shell脚本,包括命令封装示例,如apt更新、安装MongoDB等,并涉及基础的输入输出操作和文件权限设置。此外,还展示了如何通过脚本进行删除操作和系统重启,适合初学者了解shell脚本的基本使用。
摘要由CSDN通过智能技术生成

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"
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值