linux shell脚本攻略03-数组与关联数组

Shell-数组与数学运算 参考书籍 Linux shell 脚本攻略 数组和关联数组 数组分类 普通数组:只能使用整数作为数组索引。 关联数组:可以使用字符串作为数组索引。 定义数组 单行中使用一列值来定义:array_var=(1 2 3 4 5 6) #存储在以0为起始索引的连续位置上 定义为一组 索引——值对 array_var[0]="test1" array_var[1]="test... 阅读详情

定义数组
①单行中使用一列值来定义一个索引

array_var=(1 2 3 4 5 6),这些值会被存储在以0为起始索引的连续位置上

②还可以将数组定义成一组“索引-值”

array_var[0]="test1"
array_var[1]="test2"

数组的打印

echo ${array_var[0]}

打印数组清单,数组内所有的值

echo ${array_var[*]}
或者
echo ${array_var[@]}

打印数组长度

echo ${#array_var[*]}

获取数组索引信息

echo ${!array_var[*]}

关联数组
关联数组中,我们可以使用任意的文本作为数据索引,首先需要声明

declare -A array_var

然后初始化数组

array_val1=([guodd]=100 [jiang]=1000)

或者

array_val1[guodd]=100
array_val1[jiang]=101010

打印

echo ${array_val1[guodd]}  输出100

打印数组索引信息

echo ${!array_val1[*]}
或者
echo ${!array_val1[@]}

创建别名alias
alias可以给命令创建一个别名,但是只是临时生效,可以将其写入到/.bashrc中,因为每当启动一个新的shell进程时,都会执行/.bashrc中的命令
创建一个别名,删除原始文件的同时,在backup中保留副本

alias rm='cp $@ ~/backup && rm $@'

注意:
有的时候别名也会造成安全问题,如不想使用别名,可以使用\进行转义;在不可信的环境下执行命令,加一个\转义符号,来忽略可能存在的别名设置

Linux Shell学习资料:编程艺术与实战攻略 Linux Shell 是 Linux 系统下的一个用户与系统交互的命令解释器,是用户与内核之间通信的桥梁。它提供了一个界面,允许用户执行命令,运行程序,并且控制计算机。Shell 作为一种编程语言,拥有自己的语法,可以编写脚本实现自动化任务。在Shell编程中,变量是对数据的抽象,用于存储临时信息和传递数据。变量的定义很简单,只需在变量名前加上一个美元符号即可。Shell中的变量无需声明类型,它们可以存储不同类型的数据。/bin/bash# 定义变量并赋值# 输出变量内容。 阅读详情

相关推荐

ADS新手必看:用Filter DesignGuide快速搞定一个4GHz LC低通滤波器(附保姆级避坑指南)

本文为ADS新手提供了4GHz LC低通滤波器的完整设计流程,重点介绍了如何使用Filter DesignGuide避免参数设置陷阱、正确解读仿真结果以及解决实际电路与理论值的偏差问题。通过真实工程案例,详细讲解了工程创建、Filter DesignGuide配置、电路优化、仿真设置及实际工程中的进阶技巧,帮助工程师快速掌握LC滤波器设计。

weixin_30878501的博客 302

Linux脚本关联,每日一Shell(4) 数组和关联数组

一、普通数组(索引数组)基本语法1. 定义数组:array_var=(1 2 3 4 5 6)或者:array_var=([0]=1 [1]=2 [2]=3 [3]=4 [4]=5 [5]=6)相当于:array_var[0]=1array_var[1]=2array_var[2]=3array_var[3]=4array_var[4]=5array_var[5]=62. 打印数组的内容echo ...

weixin_28454475的博客 256

在VSCode中使用LaTex+(grammarly语法检测,chatgpt翻译,Sumatra PDF 轻量级pdf阅读器)

整个文章分为以下几个内容,打 * 的是必须要安装的。

u011895157的博客 2万+

Linux技能卡—数组

在linux中数组的使用。

不待见的博客 458

单相PWM整流器搭建训练——(一)拓扑原理介绍

单相整流器是一种将交流电转换为直流电的设备,主要由变压器、整流元件和滤波电路组成。变压器将输入的交流电压转换为适合整流的较低电压,整流元件(如二极管)利用其单向导电性将交流电转换为脉动直流电,最后滤波电路去除脉动直流电中的纹波,输出较为平滑的直流电,从而实现交流到直流的转换,广泛应用于各类电源设备中。

DikouNass的博客 1590

六自由度机器人(机械臂)运动学建模及运动规划系列(四)——轨迹规划

本篇介绍了六轴机器人关节空间以及笛卡尔空间轨迹规划的简单方法,并给出了一种几何解法,以简化规划过程,并提供了简单的Matlab轨迹规划函数介绍。

weixin_47849087的博客 5万+

linux sh脚本数组,UNIX sh(Bourne Shell)脚本里面使用数组的两种方法

sh 不像 bash 和 ksh 那样可以非常方便的定义和使用数组,但是可以通过其它方式来模拟数组。【方法1】通过 set 命令和位置参数来模拟数组# 定义数组set 'word 1' word2 word3# 输出数组的第一个元素echo $1# 输出数组的第二个元素echo $2# 输出数组的第三个元素echo $3# 输出数组的所有元素echo $*echo $@# 向数组中增加一个元素se...

weixin_30182831的博客 329

C#上位机面试必问30题:机器视觉+工业通信+性能优化(含答案解析)

工业通信:围绕“稳定性”展开,重点答异常处理、断线重连、资源释放;机器视觉:围绕“精度+速度”展开,重点答预处理、ROI、参数优化;性能优化:围绕“UI不卡、内存不泄、效率不低”展开,重点答异步、限流、资源复用;面试加分项:结合实际项目案例(如“我在XX项目中用信号量解决了多设备并发卡顿问题”)。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1512

Shell脚本攻略05-数组和关联数组

概述之前梳理的博文 Shell 数组 http://blog.youkuaiyun.com/yangshangwei/article/details/52372608数组是shell脚本非常重要的组成部分,它借助索引将多个独立的数据存储为一个集合。普通数组只能使用整数作为数组索引。 Bash也支持关联数组,它可以使用字符串作为数组索引。在很多情况下,采用字符串式索引更容易理解,这时候关联数组就派上用场了。

小工匠 2万+

把复杂计算推到数据库里:ABAP CDS View Table Function 从原理到落地实践

摘要:本文深入解析ABAP CDS Table Function技术,重点探讨其在复杂业务场景下的应用价值。当CDS View无法满足窗口函数、递归计算等高级需求时,Table Function通过结合CDS类型系统与AMDP的数据库原生计算能力,成为关键解决方案。文章详细介绍了Table Function的架构设计(CDS实体声明+AMDP实现)、客户端处理机制、开发传输流程中的注意事项,并通过航班数据示例展示最小实现闭环。这项技术特别适用于需要将复杂计算下推到数据库层的场景,能显著提升RAP和OData

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2303

Android AVB 分析(十二)嵌入式设备安全中的 dm-verity 简介

上一篇 《Android AVB 分析(十一)bootloader 是如何进行 verify boot 检查的?》 分析了 bootloader 中是如何调用 libavb 函数库验证 vbmeta 和 boot 等分区的。接下来就打算写一篇介绍 dm-verity 原理的文章,然后再写一篇徒手 dm-verity 实践的文章,结果偶然发现了本篇的英文原版。写得太好,我觉得自己完全没有必要再写原理了。由于原文是英文,有些英语不太好的朋友不一定能完全理解。我花了点时间,结合 AI 将英语原文翻译成中文。

洛奇看世界 3602

linux的shell学习笔记

shell脚本第一行写明解释器的路径: #!/bin/bash运行脚本两种方式:使用bash命令运行shell文件,或授予脚本文件执行权限,可直接执行文件shell启动时,一开始执行一组命令来定义提问文本、颜色等设置,命令存放在~/.bashrc中登录shell放在~/.bash_profileshell历史记录文件~/.bash_historybash中每个命令或命令序列通过使用分号或...

aizhangque5011的博客 179

Coze工作流的代码无法安装第三方模块(依赖)怎么办?(如何解决Coze工作流代码缺少模块(依赖)的问题)

Coze工作流的代码无法安装第三方模块(依赖)怎么办?(如何解决Coze工作流代码缺少模块(依赖)的问题)

XiaoqiangClub的博客 4366

linux shell脚本攻略

llo;hello  的第二个hello会被当做命令执行 echo -n 忽略换行 echo -e 输出的内容会被转移     printf  %-5s 打印字符串,- 表示左对齐,不到5位的用空格替代 $s格式化字符串,%c是替换字符,%d是数字,%f是浮点数 输出带色彩的文件和背景 echo -e "\e[1;45m \e[1;31m sssssssssssssss \e[0m"   变量的一些简单实用 var=hello 输出var变量 echo $va

我的博客 462

深度学习工具包 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")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

linux shell脚本攻略笔记,《linux shell 脚本攻略》笔记1

引用自《linux shell脚本攻略》### echo不加引号和使用单引号都是原样输出,不加引号时分号被认为是命令结束,单引号中无法输出单引号echo -n #不换行输出echo -e "1\t2" #使用转义字符时-e参数echo -e "\e[31m hello" #使用红色文字显示hello,\e[0m重置回默认颜色,30开始文...

weixin_39717443的博客 200

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

《Linux_Shell脚本攻略.第3版》读书笔记

嘻嘻,生活加油 ¥_¥ ,希望可以赚好多钱钱

山河已无恙 1120

《Linux Shell脚本攻略》学习笔记-第一章

《Linux Shell脚本攻略》学习笔记-第一章 小试牛刀

Protocol Stack | 传输与通信 708

linux shell脚本攻略 第2版 ,linuxshell脚本攻略 第2版

linuxshell脚本攻略 第2版是一本LinuxShell使用手册,由资深GNU/Linux用户Shantanu Tushar和Sarath Lakshman两人共同编著,门佳翻译。本书向读者展现了如何有效地利用shell完成复杂的任务。从shell的基础知识开始,学习简单命令的用法,对各类文件进行操作。随后讲解了文本处理、Web交互、备份、监视以及其他系统管理任务。第2版进行了全面修订,精选...

weixin_30342363的博客 402

Linux Shell脚本攻略-重定向操作符+数组和关联数组

工作原理 重定向操作符(>和>>)可以将输出发送到文件中,而不是终端 默认情况下,重定向操作针对的是标准输出,如果想使用特定的文件描述符,必须将描述符编号置于操作符之前 >等同于1>,>>等同于1>> 处理错误时,来自stderr的输出被倾倒入文件/dev/null中,/dev/null是一个特殊的设备文件,它会丢弃接收到的任何数据,null设备通常也被称为黑洞,因为凡是进入其中的数据都将一去不复返 补充内容 从stdin读取输入的命令能以多种方式接收数

Arkardia的博客 478

linux shell脚本攻略下载,Linux Shell脚本攻略

《Linux Shell脚本攻略》编辑推荐:天才程序员的独门攻略:准备,动手,一举成功!,针对110多个真实问题,展示令人难以置信的高超解法,化繁为简,几行脚本完成复杂任务。《Linux Shell脚本攻略》通过细致剖析实际应用中的110多个案例,使许多看似复杂的Linux shell脚本任务迎刃而解。作者在Linux shell脚本方面的经验,使他能够以一种相当清晰且友好的方式有效地分享他的知...

weixin_33641391的博客 468

linux_shell脚本攻略第一章笔记

Linux_shell脚本攻略(第三版)笔记,只抄录了笔者需要的一些知识点,仅供笔记使用,后续章节会陆续更新。 电子版书籍: 链接:https://pan.baidu.com/s/1Tti3s4tQaDnUdkpS0doIWQ 提取码:4kq5

weixin_43515220的博客 1235

shell脚本耕升(一)

文件描述符 文件描述符是与一个打开的文件或数据流相关联的整数。文件描述符0、1以及2是系统预留的。 0——stdin(标准输人) 1——stdout(标准输出) 2——stderr(标准错误) 例如我们在源码安装mysql初始化的时候会有密码需要暂时保存一下那我们可以使用echo将输出文本重定向到一个文件中 [root@zzyyssxx ~]# echo '123456' > pwd.txt [root@zzyyssxx ~]# cat pwd.txt 123456 [root@zzyyssxx

满堂花醉三千客,一剑霜寒十四州 2457

linux 如何将一个文本文件元素创建一个数组,Linux脚本攻略学习笔记之数组和别名...

一、数组1、数组定义2、数组定义3、打印数组元素内容4、以清单形式打印出数组的所有值5、打印数组长度(即数组中元素的个数)6、关联数组7、列出数组索引二、别名1、 创建别名2、 永久别名3、删除别名4、实例演示5、对别名进行转义一、数组1、数组定义数组是shell脚本非常重要的组成部分,它借助于索引将多个独立的数据存储为一个集合。普通数组只能使用整数作为数组索引。Bash也支持关联数组。它可以使用...

weixin_39534978的博客 603

Linux Shell脚本攻略-Shell语法

变量 每一个变量的值都是字符串 定义:tuyou='涂有';等号两边不能有空格;双引号内可写变量,单引号不行;tuyou=$(ll)在内容中执行变量 清除:unset tuyou; 取值:$tuyou、${tuyou}; 打印:echo $tuyou; 获取变量长度:${#var} 设为环境变量:export tuyou; 数值运算符 整数运算符: let命令可以直接执行基本的算术操作。当使...

Code changes the world! 408

linux ssh脚本攻略,Linux Shell 脚本攻略

1.1 简介1 打开终端后,就会出现一个提示符,形式通常如下username@hostname$ 或者root@hostname#2 $表示的是普通用户,#表示的是超级用户。超级用户是Linux中权限最高的用户3 有两种运行脚本的方式sh script.sh 或者是 path script (path是脚本所在的目录)4 在bash中每个命令是通过分号";"来分开的1.2 终端打印1 echo是用...

weixin_36256447的博客 506
上一篇: linux shell脚本攻略02-算术运算
下一篇: linux shell脚本攻略04-将命令序列的输出读入变量,管道
Java_Soldier
博客等级 码龄10年 27粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值