首页 > TAG信息列表 > rhel7pc1

linux中创建自定义函数、加载自定义函数、调用自定义函数

  1、创建自定义函数 格式: function name {   command } [root@rhel7pc1 test]# ls test.sh [root@rhel7pc1 test]# cat test.sh ## shell中创建函数格式 #!/bin/bash function fun_test { echo "hello world!" }   2、加载、调用函数 [root@rhel7pc1 test]# ls

linux系统中系统环境变量和自定义变量

  1、查看系统环境变量:env、export 2、查看自定义变量: set、declare   测试系统环境变量: [root@rhel7pc1 test]# ls [root@rhel7pc1 test]# env > a.txt && export > b.txt ## 将env和export命令的输出结果保存为文件 [root@rhel7pc1 test]# wc -l * ## 统计行数 25 a.txt

linux中取随机数

  1、$RANDOM $RANDOM 的默认范围是 [0, 32767] [root@rhel7pc1 test]# echo $RANDOM % 100 + 1 | bc 80 [root@rhel7pc1 test]# echo $RANDOM % 100 + 1 | bc 10 [root@rhel7pc1 test]# echo $RANDOM % 100 + 1 | bc 43 [root@rhel7pc1 test]# echo $RANDOM % 100 + 1 | bc 45

linux 中输出匹配行的下一行

  1、 [root@rhel7pc1 test]# ls a.txt [root@rhel7pc1 test]# cat a.txt 1 k d f 2 x c g 3 z c b 4 e w e 5 z c f 6 e d g [root@rhel7pc1 test]# sed -n '/x/{n;p}' a.txt ## 输出匹配x行的下一行 3 z c b   2、 [root@rhel7pc1 test]# ls a.txt [root@rhel7pc1 test]#

linux中while循环

  1、 [root@rhel7pc1 test]# ls test.sh [root@rhel7pc1 test]# cat test.sh #!/bin/bash NUM=10 while [ $NUM -gt 0 ] ## 循环条件 do echo "$NUM xxxx" let NUM-- ## 循环变量的变化 done [root@rhel7pc1 test]# bash test.sh 10 xxxx 9 xxxx 8 xxxx