文章分类 - shell知识
摘要:#!/usr/bin/expect set timeout 10 set username [lindex $argv 0] set password [lindex $argv 1] set hostname [lindex $argv 2] spawn ssh-copy-id -i /root/
阅读全文
摘要:#man test -n STRING the length of STRING is nonzero STRING equivalent to -n STRING -z STRING the length of STRING is zero STRING1 = STRING2 the string
阅读全文
摘要:[root@web02-7 scripts]# echo `echo {1..10}|tr " " "+"`=`echo {1..10}|tr " " "+"|bc` 1+2+3+4+5+6+7+8+9+10=55 [root@web02-7 scripts]# echo `seq -s "+" "10"`=`seq -s "+" "10"|bc` 1+2+3+4+5+6+7+8+9+10=55...
阅读全文
摘要:[root@web02-7 scripts]# time for i in $(seq 11111);do count=${#chars};done; real 0m0.187s user 0m0.090s sys 0m0.002s [root@web02-7 scripts]# time for i in $(seq 11111);do count=`echo ${chars}|wc -L`...
阅读全文
摘要:[root@web02-7 scripts]# which ssh-copy-id/usr/bin/ssh-copy-id
阅读全文
摘要:[root@web02-7 scripts]# abc="ni hao zhong guo ren" [root@web02-7 scripts]# echo ${#abc} #第一种 20 [root@web02-7 scripts]# echo $abc|wc -L #第二种 20 ...
阅读全文
摘要:[root@web02-7 scripts]# cat calc.sh #!/bin/bash [ $# -ne 2 ] && { echo "you must input tow num:$0 arg1 arg2" exit 1 } expr $1 + 0 &>/dev/null [ $? -eq 0 ] ||{ echo "you must input $1 rigth nu...
阅读全文
摘要:[root@rsync-41 ~]# result=${test:-UNSET} [root@rsync-41 ~]# echo $result UNSET [root@rsync-41 ~]# test="abc" [root@rsync-41 ~]# echo $result UNSET [root@rsync-41 ~]# result=${test:-UNSET} #通知 [roo...
阅读全文
摘要:[root@rsync-41 ~]# cat /etc/init.d/rpcbind #! /bin/sh # # rpcbind Start/Stop RPCbind # # chkconfig: 2345 13 87 # description: The rpcbind utility is a server that converts RPC program \ # ...
阅读全文
摘要:[root@rsync-41 ~]# set -- "i am" successful xusx #通过set设置参数 [root@rsync-41 ~]# echo $1 i am [root@rsync-41 ~]# echo $2 successful [root@rsync-41 ~]# echo $3 xusx [root@rsync-41 ~]# echo $@ i a...
阅读全文
摘要:[root@web02-7 ~]# cat /server/scripts/dir_base.sh #!/bin/bash dirname $0 basename $0 [root@web02-7 ~]# sh /server/scripts/dir_base.sh /server/scripts dir_base.sh [root@web02-7 scripts]# ec...
阅读全文
摘要:$0:获取当前执行的Shell脚本的文件名,如果执行脚本包含了路径,那么就包括脚本路径 $n:获取当前执行的Shell脚本的第n个参数值,n=1..9,当n=0时表示脚本的文件名。当n大于9,需要大括号,${10} $#:获取当前执行的Shell脚本后面接的参数的总个数 $*:获取当前执行的Shel
阅读全文
摘要:1、环境变量(全局变量) 3个命令显示变量值:set、env、declare env declare set -o 2、普通变量(局部变量) 在登录Linux系统并启动一个bash shell时,默认情况下bash会在若干个文件中查找环境变量的设置。这些文件可统称为系统环境文件。bash检查的环境变
阅读全文

浙公网安备 33010602011771号