摘要: 首先要区分shell语句的执行后果和shell操作符的返回值:echo "abcd"语句的执行后果是打印abcd,并非这个语句的返回值是abcd。$var表达式中$操作符的返回值是变量var的值。``或$()操作符能够将其包裹的shell语句的打印结果作为返... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(205) 评论(0) 推荐(0) 编辑
摘要: let命令:i1=2 i2=3let res=i1+$i2 #‘=’和‘+’前后不能有空格,变量前可以加‘$’符号也可不加。echo $res #5#以下两种情况不常用let res=1==3; echo $res #0let res=1!=3; e... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(276) 评论(0) 推荐(0) 编辑
摘要: alias命令设置别名:alias cls="clear"设置的别名会在当前bash退出时失效,可以将命令写入~/.bashrc:echo 'alias cls="clear"' >> ~/.bashrc若想跳过使用别名而使用原始命令,可在命令前加\符号:\... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 获取终端的行列信息:tput lines #24tput cols #80不显示输入的内容:#!/bin/bashecho -n password:stty -echo #禁止将输出发送到终端read passwordstty echo #允许将输出... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(486) 评论(0) 推荐(0) 编辑
摘要: 定义函数:#!/bin/bash#定义:function f1(){ echo $1, $2 #打印参数1,参数2 echo $@ #以列表方式一次性打印所有参数 echo $* #类似于$@,但是参数作为单个实体 return ... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(84) 评论(0) 推荐(0) 编辑
摘要: for:#打印123for i in {1,2,3}; do echo -n $idone#打印abcdfor i in {a..d}; do echo -n $idone#可以用这种循环方式for ((i=0; i2"else echo ... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 注意:使用shell工具选择不同配色方案会影响颜色的显示。几种颜色:echo -e "\033[34m[ testTEST ]\033[0m"echo -e "\033[32m[ testTEST ]\033[0m"echo -e "\033[31m\033... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(502) 评论(0) 推荐(0) 编辑
摘要: 挖矿就是在寻找sha256d值小的随机数。min="1"; time for i in {660000..670000}; do r=`echo -n $i | sha256sum`; if [ "$r" \< "$min" ]; then min=$r; ... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(160) 评论(0) 推荐(0) 编辑
摘要: shell脚本文件(t.sh)内容:#!/bin/bashecho "脚本文件名:$0"echo "参数1:$1"echo "参数2:$2"echo "参数3:$3"执行脚本:chmod +x t.sh #赋予脚本文件可执行权限./t.sh a 1 #执行脚... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(5787) 评论(0) 推荐(0) 编辑
摘要: 重定向:echo -n "hello" > hello.txtecho " world" >> hello.txtcat hello.txt #hello world# 将标准输出和标准出错都输出到/dev/null,即丢弃cat hello.txt > ... 阅读全文
posted @ 2018-12-20 08:59 xuejianbest 阅读(136) 评论(0) 推荐(0) 编辑