首页 > 系统相关 >shell script define functions

shell script define functions

时间:2022-08-29 15:03:41浏览次数:50  
标签:function functions shell script echo Progress 033 define

As we all know, shell scripts can define functions

Here are some of the functions I use

1.Defines a function that displays a progress bar

[root@ali-devan ~]# cat progress.sh 

#!/bin/bash

function Progress() {

i=''

echo -e "\033[32m$1\033[0m"

for ((j=0;$j<=100;j++))

do

 printf "Progress:[%-100s]%d%%\r" $i $j

 sleep 0.05

 i=#$i

done

}

Progress "System will reboot"

echo

reboot

#(The purpose of this script is to restart the system after five seconds, and the process is visually visible)

2.Defines a function that shows whether a script executes correctly or wrongly for each command

[root@ali-devan ~]# cat judge.sh 

#!/bin/bash

function judge() {

  if [ $? -eq 0 ];then 

    echo -e "\033[32m$1======>success\033[0m" 

  else 

    echo -e "\033[31m$1======>fail\033[0m" 

  fi

}

ls

judge "Displays the files in the current directory"

#(The purpose of this script is to check whether each command is executed successfully)

标签:function,functions,shell,script,echo,Progress,033,define
From: https://www.cnblogs.com/demoduan/p/16635928.html

相关文章

  • android root 运行 shell
    publicclassshell{staticvoidshell(Stringsh)throwsException{try{Processsu=Runtime.getRuntime().exec("su");Da......
  • 报错:ReferenceError: __dirname is not defined in ES module scope
    报错:__dirnameisnotdefinedinESmodulescope前言新版NodeJS支持通过ESM方式导入模块,代码如://CommonJS规范(旧)const{readFileSync,writeFileSync}=r......
  • shell脚本LNMP
    #!/bin/bash#安装nginx服务#########安装nginx服务################systemctlstopfirewalldsystemctldisablefirewalldsetenforce0#安装依赖包yum-yinstal......
  • PowerShell教程 - 程序性能和BUG分析工具
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。程序性能和BUG分析工具https://hibernatingrhinos.com/products/efprofhttps://s......
  • PowerShell教程 - 异步处理(Asynchronous Processing)
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。异步处理(AsynchronousProcessing)休眠(Sleep)指定时间Start-Sleep实例:休眠1秒S......
  • PowerShell教程 - 模块管理(Modules Management)
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。模块管理(ModulesManagement)模块和管理单元(ModulesandSnap-Ins)Moduleswerein......
  • linux-shell
    shellShell入门创建hellworld.sh文件多命令处理......
  • Linux Kernel in a Nutshell - 7
    CustomizingaKernel原文链接我的博客以·问题·做关键字搜索,还有问题构建你自己的Linux内核版本最困难的部分,应该就是确定哪一个驱动以及配置选项是你的设备需要的......
  • Linux Kernel in a Nutshell - 8
    KernelConfigurationRecipes原文链接我的博客前面介绍了重新配置内核的机制,本章介绍制作自己的内核通常会遇到的那些问题,并给出对应指令来处理它。DisksLinux内核......
  • PHP 中的三元运算符和or表达式对比[defined() or define()]
    在php代码中我们经常看到这样的写法:$max=$a>$b?$a:$b;mysql_connect($user,$passwd,$db)ordie($mess);下面对这两种常见的写法做以下说明:第一种:典型的三元运算......