随笔分类 -  Bash

摘要:echo $PATH | tr : \\n echo $PATH | sed '#:#\n#g' echo $PATH | awk 'BEGIN{RS=":"}{print}' echo $PATH | awk '{gsub(/:/,"\n");print}' IFS=: read -ra entr 阅读全文
posted @ 2024-01-29 17:49 ascertain 阅读(1) 评论(0) 推荐(0) 编辑
摘要:$@ "$@" $* "$*" a.sh echo "$@" echo $@ echo "$*" echo $* b.sh "$@" b.sh $@ b.sh "$*" b.sh $* b.sh echo $# for param; do echo "param = $param" done 阅读全文
posted @ 2023-04-09 23:29 ascertain 阅读(12) 评论(0) 推荐(0) 编辑
摘要:-a name 替换command程序名 作为第0个参数 -c Execute COMMAND with an empty environment -l Place a dash in the zeroth argument to COMMAND Execute command, replacing 阅读全文
posted @ 2023-01-27 19:12 ascertain 阅读(87) 评论(0) 推荐(0) 编辑
摘要:bash [options] [command_string | file] -c If then -c option is present, then commands are read from the first non-option argument command_string. If t 阅读全文
posted @ 2023-01-23 12:46 ascertain 阅读(65) 评论(0) 推荐(0) 编辑
摘要:for param #!/usr/bin/env -vS bash for param;do echo $param done for ${!i} #!/usr/bin/env -vS bash for ((i=1;i<=$#;++i)); do echo ${!i} done $* $@ shif 阅读全文
posted @ 2023-01-23 11:27 ascertain 阅读(20) 评论(0) 推荐(0) 编辑
摘要:history相关环境变量 HISTIGNORE export HISTIGNORE='pwd:ls:ls -l:exit' will not log command pwd ls, ls -a会记录, 即加参数会记录 HISTCONTROL export HISTCONTROL='ignoredu 阅读全文
posted @ 2022-10-16 18:20 ascertain 阅读(25) 评论(0) 推荐(0) 编辑
摘要:函数 #!/bin/bash function b(){ for i in `seq 1 $2`;do echo -n "$1" done } b = 1 printf printf '=%.0s' {1..10} printf %10s | tr ' ' = seq tr seq -s= 10 | 阅读全文
posted @ 2022-09-28 17:28 ascertain 阅读(91) 评论(0) 推荐(0) 编辑
摘要:dchelper.sh #!/bin/bash # global variables # scriptDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) scriptDir='' repositoryDir='' devopsHost='' dbHos 阅读全文
posted @ 2022-09-28 16:06 ascertain 阅读(17) 评论(0) 推荐(0) 编辑
摘要:function containsElement() { local n=$# # number of arguments local value=${!n} # last of arguments echo "${@:2}" echo "${@:0}" echo number of argumen 阅读全文
posted @ 2022-08-15 16:12 ascertain 阅读(30) 评论(0) 推荐(0) 编辑
摘要:pathmunge函数是RHEL系/etc/profile中定义的一个函数, 用来添加路径到PATH环境变量中, 在/etc/profile最后使用unset -f pathmunge取消了函数定义, 故shell中没有此函数定义 第一版: pathmunge() { if ! echo $PATH 阅读全文
posted @ 2022-07-17 14:44 ascertain 阅读(497) 评论(0) 推荐(0) 编辑
摘要:Function system() awk 'BEGIN{system("pwd")}' | pipe echo sh601236 | awk '{cmd="curl -s -XGET http://hq.sinajs.cn/list="$0;print cmd | "sh - | iconv -f 阅读全文
posted @ 2021-12-08 17:57 ascertain 阅读(18) 评论(0) 推荐(0) 编辑
摘要:三台机器 只循环一次 两种方式一样 for循环没有问题 -d:指定读取行的结束符号。默认结束符号为换行符。 阅读全文
posted @ 2021-08-13 17:15 ascertain 阅读(234) 评论(0) 推荐(0) 编辑
摘要:分行查看PATH echo -e ${PATH//:/'\n'} ${param-value} 有时候,会看到 这种 用法 后跟 - 的目的是为了防止引用未设置的变量时报错 nocaseglob nocasematch 阅读全文
posted @ 2021-07-16 10:49 ascertain 阅读(31) 评论(0) 推荐(0) 编辑
摘要:a b c d e f g h i j k l m n o p q r s t u v w x y z 默认使用所有, 且于最后 -n --max-args=MAX-ARGS use at most MAX-ARGS arguments at a time 使用 -n1 使 xargs 每次传入一个 阅读全文
posted @ 2021-06-24 14:06 ascertain 阅读(48) 评论(0) 推荐(0) 编辑
摘要:#!/bin/env bash rootdir=/mnt/sysroot libcp() { for i in `ldd $1|grep -o '/[^[:blank:]]*'`;do libdir=`dirname $i` [[ -d $rootdir$libdir ]] || mkdir -p 阅读全文
posted @ 2021-05-09 11:51 ascertain 阅读(42) 评论(0) 推荐(0) 编辑
摘要:#!/bin/env bash username=$1 { id $username [[ $? -ne 0 ]] && useradd --comment '$username' $username && echo $username|passwd --stdin $username } >& / 阅读全文
posted @ 2021-05-09 11:47 ascertain 阅读(58) 评论(0) 推荐(0) 编辑
摘要:1.交互式命令 不会执行 ip a命令,直接退出 #!/bin/env expect set timeout 3 spawn ssh -l root 172.16.30.102 expect { "yes/no" { send "yes\n";exp_continue } "password" { 阅读全文
posted @ 2021-01-20 15:07 ascertain 阅读(126) 评论(0) 推荐(0) 编辑
摘要:Linux系统下,使用默认用户root。远程target机器的主目录下有个脚本test.sh,可执行权限,内容只有一条命令:sleep 10 在本地机器上执行 ssh target "nohup ./test.sh &",结果ssh不立即退出,等test.sh执行完毕之后才退出。一般我们使用nohu 阅读全文
posted @ 2021-01-08 12:05 ascertain 阅读(1124) 评论(0) 推荐(0) 编辑
摘要:彻底搞懂shell的高级I/O重定向 - 骏马金龙 - 博客园 (cnblogs.com) 软件设计认为,程序应该有一个数据来源、数据出口和报告错误的地方。在Linux系统中,它们分别使用描述符0、1、2来表示,这3个描述符默认的目标文件(设备)分别是/dev/stdin、/dev/stdout、/ 阅读全文
posted @ 2020-12-10 16:26 ascertain 阅读(474) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示