ICode9

精准搜索请尝试: 精确搜索
  • linux中创建自定义函数、加载自定义函数、调用自定义函数2022-04-16 18:31:34

      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系统中系统环境变量和自定义变量2022-04-16 18:03:21

      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中取随机数2022-04-16 12:03:18

      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 中输出匹配行的下一行2022-04-10 14:31:35

      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循环2022-04-05 20:05:02

      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

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有