当前位置:网站首页>shell编程
shell编程
2022-07-26 06:37:00 【noravinsc】
while循环
#!/bin/bash
i=1
sum=0
while ((i <= 100))
do
((sum += i))
((i++))
done
echo "The sum is: $sum"
参考:https://www.jb51.net/article/201771.htm
读取文件行数
awk 'END{print NR}' test.sh
参考:https://www.bilibili.com/read/cv16036091/
读取文件最后一行
tail -n 1 file.txt
参考:https://www.csdn.net/tags/MtzaEgysODk5NjMtYmxvZwO0O0OO0O0O.html
读取并执行语句
cmd=$line
# 打印指令
echo $cmd
# 执行指令
echo $cmd | sh
参考:https://blog.csdn.net/u010132847/article/details/113141583
删除最后一行
sed -i '$d' <file>
参考:https://blog.csdn.net/sosemseo/article/details/108356945
向文件追加一行
str='gg'
sed -i '$a\'$str /opt/b.txt
参考:https://blog.csdn.net/yabingshi_tech/article/details/114364672
bash脚本nohup执行
nohup bash xxx.sh > xxx.log &
边栏推荐
- Why the server is stuck
- 原生高性能抓包工具Proxyman,送给爱学习的你
- Integrated design of signal processing systems - Design of solver functions (continuous and discrete time systems)
- RNN recurrent neural network
- [day04_0421] C language multiple choice questions
- C language file operation
- Servlet cannot directly obtain JSON format data in request request
- 快速排序(quick-sort)
- CONDA virtual environment envs directory is empty
- 源代码加密技术发展阶段
猜你喜欢

【C语言】文件操作
![[fault diagnosis] bearing fault diagnosis based on Bayesian optimization support vector machine with matlab code](/img/9e/138e4b160fa9bd6486fac44a788d09.png)
[fault diagnosis] bearing fault diagnosis based on Bayesian optimization support vector machine with matlab code

『牛客|每日一题』 栈的压入、弹出序列

Markdown add Emoji expression

【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦

『牛客|每日一题』点击消除

Torth file read vulnerability (cnvd-2020-27769)

The real epidemic situation in the United States, do not easily "bottom" 2020-03-23

A tool for quickly switching local host files -- switchhosts
![[1]数学建模基础入门知识](/img/29/90b1c7533e9443852758d10080e239.png)
[1]数学建模基础入门知识
随机推荐
定义方法时为什么使用static关键字
快速排序(quick-sort)
JS date details, string to date
Quick sort
[day02_0419] C language multiple choice questions
数据库中varchar和Nvarchar区别与联系
Valid bracket sequence of "Niuke | daily question"
力扣5: 最长回文子串
【pytorch】图片增广
Gdown Access denied:Cannot retrieve the public link of the file.
『牛客|每日一题』逆波兰表达式
Database and the future of open source
力扣——4. 寻找两个正序数组的中位数
[day_070425] Fibonacci series
[day04_0421] C language multiple choice questions
Decomposing a positive integer into prime factors requires decomposing into as many factors as possible.
Use scanner to get multiple data types from the keyboard
UIToolkit工具模板工程
[specified interval inversion in BM2 linked list]
Overview of image classification of vision transformer must read series