
shell
张超帅
哈哈哈哈哈哈
展开
-
shell小作业
1)使用shell程序可以完成哪些类型的工作? 2)使用shell编程时,如何将编写完成的shell程序提交给系统运行? Bash test.sh Bash ./test.sh ——./代表当前文件夹下 3) 写一个脚本,传递两个整数给脚本,让脚本分别计算并显示这两个整数的和,差,积,商。 #!/bin/bash calculate(){ first=${1} second=${2} ...原创 2018-07-12 10:57:16 · 805 阅读 · 0 评论 -
shell的for循环
第一种写法 #!/bin/bash for((i=1;i<=10;i++)); do ... done 第二种写法 #!/bin/bash for i in $(seq 1 10) do ... done 第三种写法 #!/bin/bash for i in {1..10} do ... done ...原创 2018-07-12 11:01:32 · 150 阅读 · 0 评论 -
shell比较两个整数大小并严格判断参数输入脚本
代码如下 #!/bin/sh [ $# -ne 2 ] && { echo "USAGE: $0 agr1 arg2 " exit 1 } expr $1 + 0 &>/dev/null if [ $? -ne 0 ] ;then echo "$1 is not int" exit 1 fi expr $2 + 0 &>...原创 2018-07-19 00:01:15 · 3353 阅读 · 0 评论 -
shell输出一堆英文字母数不大于6的单词
第一种方法${#变量} #!/bin/sh array=(I am a student study in a big classroom) for word in ${array[*]} do if [ ${#word} -le 6 ] ;then echo "$word" fi done 第二种方法 wc -L #!/bin/sh array=(I ...原创 2018-07-19 00:20:15 · 977 阅读 · 0 评论 -
shell的${}和$()的区别
$()命令替换,例如$(echo ...) ${}变量替换,例如${#word},一般情况下,$var 与 ${var} 并没有啥不一样 []算数比较用单中括号[ ]——左右留空格 shell中的注释 #号...原创 2018-07-19 00:30:32 · 1932 阅读 · 0 评论 -
shell数组批量检查网站是否异常
代码如下 #!/bin/bash [ -f /etc/init.d/functions ] && . /etc/init.d/functions array=( http://www.etiantian.org http://www.taobao.com http://www.jd.com http://10.0.0.7 ) curl_ip() { curl -o /...原创 2018-07-19 01:05:45 · 345 阅读 · 0 评论 -
shell实现在远程服务器上创建文件
首先配置username和host地址,执行下列命令 spawn ssh ${username}@${host} expect { "yes/no" { send "yes\r"; exp_continue } "password:" { send "${password}\r" } } expect "100%" send "touch /home/qapps.原创 2018-08-01 10:58:41 · 6927 阅读 · 0 评论 -
shell利用expect工具scp上传到服务器,并复制cp到其他目录
spawn激活一个scp的unix程序 spawn ssh 和spawn scp后都接一个expect,交互密码,这里不用再手动输入密码。没有expect输入密码过程,上传和复制都不会完成。 spawn ssh ${username}@${host} expect { "yes/no" { send "yes\r"; exp_continue } "password...原创 2018-08-01 15:16:50 · 1233 阅读 · 0 评论