bash

BASH scripting: n-th parameter of $@ when the index is a variable?

ぐ巨炮叔叔 提交于 2021-02-18 04:47:06
问题 I want to retrieve the n-th parameter of $@ (the list of command line parameters passed to the script), where n is stored in a variable. I tried ${$n}. For example, I want to get the 2nd command line parameter of an invocation: ./my_script.sh alpha beta gamma And the index should not be explicit but stored in a variable n. Sourcecode: n=2 echo ${$n} I would expect the output to be "beta", but I get the error: ./my_script.sh: line 2: ${$n}: bad substitution What am I doing wrong? 回答1: Try this

Shell运算符

孤街浪徒 提交于 2021-02-18 02:20:46
1)算数运算符 1)常见的算数运算符,如下图: 说明:变量a在运算符之前,输出表达式的值为a,然后a自增或自减;变量a在运算符之后,输出表达式会先自增或自减,表达式的值就是自增或自减后a的值。 常见的命令运算命令,如下图; 我们来实践一下吧, 1 [root@king scripts]# cat test.sh 2 #! /bin/ bash 3 a=$ 1 # 直接把特殊位置参数变量$1赋值给a, 4 b=$ 2 # 并且把特殊位置参数变量$2赋值给b,这样,脚本传参的内容就会赋值给a和b。 5 echo " a-b=$(($a-$b)) " 6 echo " a+b=$(($a+$b)) " 7 echo " a*b=$(($a*$b)) " 8 echo " a/b=$(($a/$b)) " 9 echo " a**b=$(($a**$b)) " 10 echo " a%b=$(($a%$b)) " 11 [root@king scripts]# sh test.sh 6 2 12 a-b= 4 13 a+b= 8 14 a*b= 12 15 a/b= 3 16 a**b= 36 17 a%b= 0 我们来模仿一下计算器吧, 1 #! /bin/ bash 2 #add, subtract, multiply and divide 3 print_usage(){      

Kubernetes 编排神器之 Helm

我的未来我决定 提交于 2021-02-17 23:56:47
什么是Kubernetes Helm?为什么要使用Helm? 前言 编写一堆Kubernetes配置文件是一件很麻烦的事情。对于一些容器,我们可能需要10多个yaml文件。维护它们是一个问题,而且在不同的环境中运行或使用相同的文件更是是一个噩梦。 我们可以使用一些 bash 技巧来替换某些值,但这是一个不好的做法。 这就是我们为什么要使用helm。 我应该提到,还有另一个很好的工具 ksonnet ,它以自己的方式进行“相同”操作。 在这篇文章中,我将介绍为什么Helm是Kubernetes应用程序必不可少的要素,将Kubernetes应用程序与Helm打包的过程,以及如何使用Helm部署可能具有的某些复杂应用程序。 为什么要使用helm 我最近在部署的微服务很复杂,我的发布文件目录中有65个以上的Kubernetes配置文件 ... o( ^▽^ )┛)。 主要问题是,我要如何把这个服务部署到多个环境中? 或者如何使用Kubernetes制作CI/CD? 当然做一些shell脚本是一个选择,但是我不是很喜欢这样做。 然后,我开始使用Kubernetes研究CI/CD pipline,发现一些团队正在将Helm集成到该过程中。 我们可以将理解为为像应用程序包那样的应用程序,在其中我们可以进行依赖管理,不同类型的钩子(安装前,升级前,安装后等),并且可以轻松升级或回滚。 安装

How do I pass an absolute path to the adb command via git bash for windows?

元气小坏坏 提交于 2021-02-17 19:04:08
问题 I'm trying to pass a unix style path to the Android adb command using a git bash (msysgit) but the shell is interpreting my path incorrectly. This is what I've tried so far: $ adb push myfile /mnt/sdcard/ failed to copy 'myfile' to 'C:/Program Files (x86)/Git/mnt/sdcard/': No such file or directory $ adb push myfile "/mnt/sdcard/" failed to copy 'myfile' to 'C:/Program Files (x86)/Git/mnt/sdcard/': No such file or directory $ adb push myfile '/mnt/sdcard/' failed to copy 'myfile' to 'C:

Use awk to find first occurrence only of string after a delimiter

半城伤御伤魂 提交于 2021-02-17 18:47:00
问题 I have a bunch of documents that all have the line, Account number: 123456789 in various locations. What I need to do is be able to parse through the files, and find the account number itself. So, awk needs to look for Account number: and return the string immediately following. For example, if it was: Account number: 1234567 awk should return: 1234567 Once it's found the first occurrence it can stop looking. But, I'm stumped. What's the right way to do this using awk ? 回答1: One way: awk -F:

Use awk to find first occurrence only of string after a delimiter

荒凉一梦 提交于 2021-02-17 18:45:37
问题 I have a bunch of documents that all have the line, Account number: 123456789 in various locations. What I need to do is be able to parse through the files, and find the account number itself. So, awk needs to look for Account number: and return the string immediately following. For example, if it was: Account number: 1234567 awk should return: 1234567 Once it's found the first occurrence it can stop looking. But, I'm stumped. What's the right way to do this using awk ? 回答1: One way: awk -F:

Use awk to find first occurrence only of string after a delimiter

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-17 18:45:16
问题 I have a bunch of documents that all have the line, Account number: 123456789 in various locations. What I need to do is be able to parse through the files, and find the account number itself. So, awk needs to look for Account number: and return the string immediately following. For example, if it was: Account number: 1234567 awk should return: 1234567 Once it's found the first occurrence it can stop looking. But, I'm stumped. What's the right way to do this using awk ? 回答1: One way: awk -F:

Use awk to find first occurrence only of string after a delimiter

北战南征 提交于 2021-02-17 18:44:19
问题 I have a bunch of documents that all have the line, Account number: 123456789 in various locations. What I need to do is be able to parse through the files, and find the account number itself. So, awk needs to look for Account number: and return the string immediately following. For example, if it was: Account number: 1234567 awk should return: 1234567 Once it's found the first occurrence it can stop looking. But, I'm stumped. What's the right way to do this using awk ? 回答1: One way: awk -F:

Use awk to find first occurrence only of string after a delimiter

╄→尐↘猪︶ㄣ 提交于 2021-02-17 18:43:20
问题 I have a bunch of documents that all have the line, Account number: 123456789 in various locations. What I need to do is be able to parse through the files, and find the account number itself. So, awk needs to look for Account number: and return the string immediately following. For example, if it was: Account number: 1234567 awk should return: 1234567 Once it's found the first occurrence it can stop looking. But, I'm stumped. What's the right way to do this using awk ? 回答1: One way: awk -F:

基于TypeScript从零重构axios

血红的双手。 提交于 2021-02-17 18:14:12
download: 基于TypeScript从零重构axios 本课程首先讲解TS的基础语法和常见用法,然后带同学使用TS去实现一个完整的axios JS库,进行完整的单元测试,最后把开发的JS库打包并发布到npm上。通过课程学习掌握axios的实现原理,修炼原生JS内功,提升职场竞争力。 适合人群 1-5年前端开发人员 技术储备要求 有良好的原生JavaScript功底 熟悉ES6常见的语法和API 1、ping(测试网络连通) 命令所在途径:/bin/ping 命令执行权限:一切用户 -c 指定ping次数 -s 指定探测时数据包的大小 2、ifconfig(查询本机网络信息) 命令所在途径:/usr/sbin/ifconfig 执行权限:root ifconfig命令运用办法 留意:下面操作运用root用户(动态修正) 命令:ifconfig 作用:用来配置网络或显现当前网络接口的状态(以本机ens33示例) ![]() 上图信息大约阐明: 第一行:up-->网卡开启状态 [在BROADCAST(播送)之后,(此处未显现)RUNNING-->网线处置衔接状态] MULTICAST-->支持组播 mtu 1500-->(Maximum Transmission Unit)最大传输单元大小为1500字节 第二行:该网卡的IP地址,子网掩码,播送地址 第三行:IPV6的配置信息