bash简介

本文会不定期更新 :) set 可以使用set命令改变shell脚本默认的执行流程。 比如 set -e 可以使得shell脚本遇到某一条命令出错( echo $? 不为0)时立即退出执行。 1 2 3 4 #/bin/bash set -e false echo you cannot see me, unless you comment out the 'set -e' flag, haha set详细文档 du 1 2 ❯ du -sh Downloads 4.1G Downloads wiki rm 1 rm $0 # 删除当前文件 for cleanup job nohup 在后台执行当前命令: 1 nohup /usr/sbin/script.sh & 默认情况下,进程是前台进程,这时就把Shell给占据了,我们无法进行其他操作,对于那些没有交互的进程, 我们希望将其在后台启动,可以在启动参数的时候加一个’&‘实现这个目的。 1 2 3 4 5 ❯ sleep 5 & [1] 34769 ✦ ❯ [1] + 34769 done sleep 5 ✦ ❯ 进程切换到后台的时候,我们把它称为job。切换到后台时会输出相关job信息,上面&的输出 [1] 34769 : [1]表示job ID 是1,11319表示进程ID是34769。切换到后台的进程,仍然可以用ps命令查看。 ...

November 17, 2021 · datewu

Neutron小记

前段时间的花了很多功夫对接k8s和openstack的kuryr-kubernetes网路组件。 学到了很多openstack的知识,今天抽出时间来整理下。 client 首先是 install openstack-cli neutron client: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/bin/bash [root@deoops ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo) #### add openstack yum repo source [root@deoops ~]# vi /etc/yum.repos.d/openstack.repo [root@deoops ~]# yum install -y python2-openstackclient openstack-neutron [root@deoops shells]# cat source export OS_PROJECT_DOMAIN_NAME=default export OS_USER_DOMAIN_NAME=default export OS_PROJECT_NAME=your_project_name export OS_USERNAME=your_use_name export OS_PASSWORD=your_pwd export OS_AUTH_URL=http://10.8.1.3:35357/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 vip 我们来创建一个virtual IP验证上一步配置的openstack source对不对 : ...

April 21, 2019 · datewu

bc语言

base 通过修改ibase和obase可以实现各种进制的转化,比如十进制和二进制和十六进制之间的转换; If you aren’t familiar with conversion between decimal, binary, and hexadecimal formats, you can use a calculator utility such as bc or dc to convert between different radix representations. For example, in bc, you can run the command obase=2; 240 to print the number 240 in binary (base 2) form. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/bin/bash ❯ bc -q ibase 10 obase 10 1+ 3 *3 10 obase=2 245 11110101 255 11111111 192 11000000 168 10101000 1 1 172 10101100 obase=16 34 22 172 AC ^D% syntax 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 bc An arbitrary precision calculator language. More information: https://manned.org/bc. - Start bc in interactive mode using the standard math library: bc -l - Calculate the result of an expression: bc <<< "(1 + 2) * 2 ^ 2" - Calculate the result of an expression and force the number of decimal places to 10: bc <<< "scale=10; 5 / 3" - Calculate the result of an expression with sine and cosine using mathlib: bc -l <<< "s(1) + c(1)"

October 22, 2018 · datewu