shell script学习笔记一


#####the fist line should be the following#####
#!/bin/bash


#####return value#####
exit n


#####Usage of read command,读键盘的输入#####
read [-pt] variable
-p: 后面可以接提示信息
-t: 后面可以接等待的秒数,这样脚本不用一直等下去

例子:
read -p "Input your name: " name;
echo $name;

#3秒内输入名字
read -p "input your name: " -t 3 name;


#####date command#####
#2 years/days/minutes/seconds ago
date1=`date --date='2 years/days/minutes/seconds ago' +%Y%m%d`
echo $date1

#2 years/days/minutes/seconds next
date2=`date --date='-2 /days/minutes/seconds ago' +%Y%m%d`
或者date2=`date --date='-2 /days/minutes/seconds next' +%Y%m%d`
echo $date2


#####数值运算#####
total=$((运算表达式))
e.g. total=$((2+3))


#####判断表达式#####
判断表达式有test指令和[]。

##test指令
当我们要检测系统上某个文件是否存在或者属性时,可以使用test指令。用&&判断真值,||判断假值。例如:
test -e ch04.sh && echo "exist" || echo "no exist"

意思就是当文件ch04.sh存在时打印"exist",不存在时打印"no exist"。

#判断字符串长度是否为0
test [-zn] string
-z: 当string为空时,返回true
-n: 当string不为空时,返回true

test -z "" && echo "empty" || echo "not empty"
#empty
test -z " " && echo "empty" || echo "not empty"
#not empty

test -n "" && echo "not empty" || echo "empty"
#empty
test -n " " && echo "not empty" || echo "empty"
#not empty


#判断字符串是否相等,注意=和!=两边要留一个空格
test str1 = str2
test str1 != str2

#逻辑与,或,非
-a(and)
-o(or)
!

##判断符号[]
注意点:
1. 在中括号内的各个元素必须有空格隔开
2. 在中括号内的变量,最好用双引号括起来
3. 在中括号内的常数,最好用单引号或者双引号括起来

例子:
yn='y'
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "equal" || echo "not equal"
#equal
Shell Script教程—提纲挈领版 以前半吊子的了解过一些Shell Script,是作为学习Linux时附带的小章节,最近实习的时候,经常会用到,都是现学现卖,查查博客,查查手册,这几天对着RUNOOB.COM整个又看了一遍,顺便记录了一下笔记。 本身RUNOOB.COM就偏简易,我这个笔记自然是简易版本的简易版,原教程链接见,Shell教程。 【本人对以下代码例子本身不享有任何权利,也不承担任何责任,仅为二次编辑与整理】 She... 阅读详情

相关推荐

RC电路(一):微分|积分

的取值不同,会导致输出波形和输入波形之间的关系也不同,由此也会产生不同的应用。输出为0,随着电容充满电,运放-输入端得到的分压为正最大值,可等效成一个电压源,且电压不可突变,此时电流反向为最大值,开始充电时的容抗为0,电压不可突变则电压差为0,运放。开始充电时的容抗为0,电压不可突变则电压差为0,运放。输入端得到的分压也不可突变,随着电容放完电,于是。,因电容上电压不能突变(来不及充电,相当于短路,由上分析可得积分运算电路中,输出为运放的负最大峰值,随着电容充满电,输出为运放的正最大峰值,随着电容放完电,

既有随处可栖的江湖,也有追风逐梦的骁勇! 1万+

shell 脚本汇总 (持续更新中)

文章目录1、计算从1到100所有整数的和2、提示用户输入一个小于100的整数,并计算从1到该数之间所有整数的和3、求从1到100所有整数的偶数和、奇数和4、逛淘宝选购商品脚本,每家商店有五种商品选购(衣服500元,裤子400元,鞋子350元,帽子150元,袜子50元),每次选购完或不买都会提示用户是否继续逛下一家商店,如果不再继续逛的话进行购物车结算总额。5、shell 计算器6、99乘法表7、等腰三角形8、直角三角形9、批量添加用户10、根据IP地址,批量检查主机状态11、猜商品价格 1、计算从1到100

Gengchenchen的博客 7963

论文笔记--Spatial-Temporal Fusion Graph Neural Networks for Traffic Flow Forecasting

Summary 在交通预测问题上,现有的框架通常利用给定的空间邻接图和复杂的机制来建模空间和时间关联。作者认为使用给定的空间邻接图会限制模型的有效时空相关性学习,并且它们通常使用单独的模块来实现空间和时间相关性,或者只使用独立的组件来捕获局部或全局的异质依赖关系,割裂了时空依赖关系。为此作者提出一种时空融合图神经网络用于交通预测。提出一种数据驱动的“时间图”生成方法,以此来补偿空间图可能没有反映的相关性。提出一种新的交通预测方法。 Problem Definition 交通预测中的挑战 以上图为

chenxino的博客 1755

shell脚本基本语法详解

编写shell脚本的时候,最前面要加上一行:#!/bin/bash,因为linux里面不仅仅只有bash一个解析器,还有其它的,它们之间的语法会有一些不同,所以最好加上这一句话,告诉系统要用这个解析器。一.shell变量shell变量和一些编程语言不同,一般shell的变量赋值的时候不用带“$”,而使用或者输出的时候要带“$”。加减乘除的时候要加两层小括号。括号外面要有一个“$”,括号里面的变量可以

_ACME_的博客 9万+

wireshark抓包分析TCP协议和用Fiddler抓包Https分析

wireshark抓包分析TCP协议和用Fiddler抓包Https分析 1.实验说明: 以某种游戏的客户端连接服务器、断开服务器为例,用wireshark抓包分析TCP协议的三次握手连接、四次握手断开,与计算机网络原理进行验证;用Fiddler抓包,分析验证一个HTTPS网站的TCP连接过程 2.实验过程: wireshark实验: (1)实验准备:安装《洛克王国》游戏客户端, 运行洛克王国客户端,打开内存资源管理器查看PID 根据PID查看洛克王国服务端的IP地址和端口号 并打开命令行运行以下命令: n

qq_42032327的博客 1258

从零开始用STM32驱动RGB屏:配置PCLK、DE同步信号的避坑指南

本文详细介绍了如何使用STM32驱动RGB接口LCD屏幕,重点解析了PCLK配置、同步信号极性和DE使能等关键参数的设置方法。通过实战代码示例和常见问题排查指南,帮助开发者避免常见配置错误,实现稳定的显示效果。特别针对800x480 IPS屏提供了优化建议和调试技巧。

sky77的博客 539

Linux(7)学习shell script

一.什么是shell script shell script 是利用 shell 的功能所寫的一個『程式 (program)』,這個程式是使用純文字檔,將一些 shell 的語法與指令(含外部指令)寫在裡面, 搭配正規表示法、管線命令與資料流重導向等功能,以達到我們所想要的處理目的。簡單的說, shell script 就像是早期 DOS 年代的批次檔 (.bat) ,最簡單的功能就是將許多指令...

weixin_38967434的博客 445

伪距单点定位推导+DOP值分析(附matlab仿真代码)

伪距单点定位公式推导、DOP值分析与matlab仿真分析

shannanshouyin的博客 2512

收藏!一篇教会你写90%的shell脚本

还不会写shell脚本?这篇文章教会你写90%的shell脚本!

Tech Station 9万+

用AI科研绘图全新升级!借助谷歌新发布模型Nano Banana pro实测一键绘制机制图与技术路线图,直接告别文字乱码与低画质

之前有同仁反馈,用Nano Banana画科研插图的时候,要么文字部分容易乱码,要么抓不住关键内容,画出来的效果反复修改后,还是达不到理想的效果。终于在Gemini 3发布没几天,万众期待的大香蕉模型也成功升级到了Pro版本,官方名称叫“Gemini 3 Pro Image”,实际上也就是我们说的Nano Banana 2。这次的Nano Banana Pro模型,不仅可以直出4K高清图,还能自定义比例,推理能力和中文文字的稳定性也得到了提升。

智能AI让学术科研更容易 1887

基于STM32、HAL库的BMP585 气压传感器 驱动程序设计

define BMP585_I2C_ADDR_PRIMARY 0x76 << 1 /* 0x76地址左移一位 */#define BMP585_I2C_ADDR_SECONDARY 0x77 << 1 /* 0x77地址左移一位 *//* I2C句柄 *//* I2C地址 *//* 设置新的温度过采样率 *//* 设置新的滤波器系数 *//* 芯片ID *//* 清除温度过采样位 *//* 转换为hPa *//* 设置新的压力过采样率 *//* 设置新的电源模式 *//* 清除压力过采样位 */

corlin6688的博客 459

Linux shell script学习笔记一

1.什么是shell script shell script 是利用 shell 的功能所写的一个程序 (program),这个程序是使用纯文字档,将一些 shell 的语法与命令(含外部命令)写在里面, 搭配正规表示法、管线命令与数据流重导向等功能,以达到我们所想要的处理目的。 2.

sinat_30919065的博客 482

RT-DETR改进策略【独家融合改进】| SPD-Conv+PPA 再次提升模型针对小目标的特征提取能力

SPD-Conv是一种新的 CNN 构建模块,用于替代传统 CNN 架构中使用的步长卷积(strided convolution)和池化(pooling)层,它由空间到深度(Space-to-depth,SPD)层和非步长卷积(non - strided convolution)层组成。

Limiiiing的博客 1154

Linux系统学习 shell script

Linux系统学习 shell script

傻傻的心动的博客 1402

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【运行Shell Script程序】

if…else三元表达式 分支结构 1.输入一个分数,判断该分数是ABCD中哪一级(A:[90,100],B:[70,90),C:[60,70),D:[0,60)) 2.输入x值,输出y的值:y={█(2x(x>5)@10-x(x<5)@x-2(x=5))┤ 3. 输入一个4位(含4位)以内的正整数,判断这个数字是几位数,并输出该数字的每位数字之和 4.输入2个数字和加减乘除中的一个符号,输出对应的结果 5.输入一个2位正整数,这个数字如果是奇数,输出各位数字之和,如果是偶数,输出各位数字之差

yxq422976的博客 2015

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【shell script】

脚本的运行方式,判断式,if语句,case语句,while循环、until循环和for循环

weixin_42504934的博客 2034

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

通过Excel自动生成Shell Script

放入指定格式字符自动生成脚本 函数1 指定数据 xxxxxxxxxx 00000123456 1900/01/01 14:57:27 -123456 ins-xxx-sky 函数 Gen “Celebrus fires content request to Pega - Se...

天空源的博客 1208

Linux学习笔记(七):Shell与Shell Script

Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。Ken Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。Shell 脚本(shell script),是一种为 shell 编写的脚本程序。

Machine Learning with Tutors 8371

shell script简介

1 什么是shell script? shell script是通过shell 的功能所写的一个program,这个程序 是使用纯文本文件,将一些shell的语法与命令写在里面 ,搭配正则式,管道命令和数据流重定向等功能,以达到我们所想要的功能。 2.1 编写第一个script #!/bin/bash # this is first shell script # printf H...

mick_hu的博客 7479

Shell Script 学习笔记

Shell Script 学习笔记 1、什么是Shell Script shell是命令行界面下让我们与操作系统沟通的一个工具接口,script是就是‘"脚本"的意思。 shell script是利用shell的功能所写的一个"程序",这个"程序"是使用纯文本文件,将一些shell的语法与命令(含外部命令)写在文件中,搭配正则表达式、管道命令与数据流重定向等功能,以达到我们想要的处理目的。

紫眸的博客 1201

项目八 学习shell script

可以使用“declare i total-SfirstnsSsecnu",也可以使用上面的方式来表示。**3,netstat命令:**查询到目前主机开启的网络服务端口(service posts)。以bash程序来运行,通过“bash shell.sh"或“sh shell.sh"来运行。当你使用直接运行的方法来处理时,系统会开辟一个新的bash来运行sh02.sh里边的内容。**1,功能:**能提供数组,循环,条件与逻辑判断等功能。3,支持排错(debug),可以更好的管理主机。

打好基础,突破瓶颈 1293

shell script 编写和执行

1. shell script shell script是针对shell写的脚本。 使用纯文本文件, 将一些shell的语法和命令写在里面,使用户能处理复杂的操作。 命令执行: 需要文件有rx权限。 当前目录下使用相对路径: ./hello.sh 或者使用绝对路径: /home/work/hello.sh 以bash命令执行:

yonggang7的专栏 4002

Shell Script字符串处理

Shell Script中字符串的字符串处理,如获取字符串长度、获取子串、移除子串以及替换操作。

Ghosind 533

shell script入门

从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁。用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操作。在Linux GUI日益完善的今天,在系统管理等领域,Shell编程仍然起着不可忽视的作用。深入地了解和熟练地掌握Shell编程,是每一个Linux用户的必修 功课之一。 Linux的Shell

gcong 8062

Shell script的语法一:基础语法

shell script 是利用 shell 的功能所写的程序 (program),这个程序使用纯文字,将一些 shell 的语法和命令(含外部命令)写在里面, 搭配正规表达式、管道命令与资料流导向等功能。 一、shell script的书写规则: 1、命令的执行是从上而下、从左至右的分析与执行。 2、命令、选项与参数间的多个空白都会被忽略掉。 3、空白行也将被忽略掉,并且 [tab] 键

heart_1014的博客 7073

Shell脚本编程(一):初识shell script

Shell简介 Shell是一个命令解释器,它是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。Shell在操作系统的最外层,负载直接与用户对话,把用户的输入解释给操作系统,并处理各种各样的操作系统的输出结果,输出到屏幕并返回给用户。这种对话方式可以是交互的方式(从键盘输入命...

dichengyan0013的博客 335
上一篇: 下用rewrite实现动态二级域名解析(转)
下一篇: shell script学习笔记二
flyingjava
博客等级 码龄20年 9粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值