定义函数

function fname()

{

  statements;

}

或者

fname()

{

  statements;

}

传递参数给函数:

fname arg1 arg2;

ex:

  函数参数定义:

fname()

{

  echo $1, $2;

  echo "$@";

  echo "$*";

  return 0;  

}

检测命令是否成功执行

#!/bin/bash
#filename:success_test.sh
cmd="ls"
$cmd
if [ $? -eq ];
then
echo "$cmd executed successfully"
else
echo "$cmd terminated unsuccessfully"
fi

shell脚本使用技巧3--函数调用的更多相关文章

  1. shell脚本常用技巧

    shell脚本常用技巧 1.获取随机字符串或数字 ~]#echo $RANDOM | md5sum | cut -c 1-6 ~]#openssl rand -base64 4 | cut -c 1- ...

  2. shell脚本使用技巧3--调试

    1.使用-x,开启shell脚本的跟踪调试功能 ex:bash -x script.sh or sh -x script.sh 2.使用set -x 和 set +x对脚本进行部分调试(输入中间的内容 ...

  3. shell脚本调试技巧

    shell脚本调试之工具——bashdb http://www.cnblogs.com/itcomputer/p/5011845.html

  4. shell脚本常规技巧

    邮件相关 发送邮件: #!/usr/bin/python import sys; import smtplib; from email.MIMEText import MIMEText mail_ho ...

  5. SHELL 脚本小技巧

    脚本很简单,直接上功能介绍及脚本,可以做模板使用: 记录日志,记录脚本开始执行时间.结束时间 usage 函数,脚本需接参数执行,避免误执行,告诉用户,这个脚本的使用方法 加锁,创建锁文件,脚本不允许 ...

  6. shell脚本小技巧

    输入参数错误时,退格会出现^H,这个时候只要在脚本顶部加一条语句:stty erase ^h就可以了 #!/bin/sh stty erase ^h

  7. shell脚本使用技巧5--字符分隔

    #!/bin/bash #filename:ifs.sh data="name,sex,rollon,location" oldIFS=$IFS IFS=, for item in ...

  8. shell脚本使用技巧4--读取字符,重复执行

    ls | cat -n > out.txt 给输出的信息加行号并导出到out.txt 利用shell生成一个独立的进程 pwd; (cd /bin; ls); pwd; 开启一个子shell,不 ...

  9. shell脚本使用技巧2

    0--stdin标准输入 1--stdout标准输出 2--stderr标准错误 重定向 echo "this is a good idea " > temp.txt tem ...

  10. Shell脚本小技巧收集

    1.使用python快速搭建一个web服务器 访问端口8000 python -m SimpleHTTPServer 2.获取文件大小 stat -c %s $file stat --printf=' ...

随机推荐

  1. python爬虫点触验证码的识别思路(图片版)

  2. 用C语言实现窗口抖动

    #include "stdafx.h" #include <stdio.h> #include<Windows.h> int main() { ; //休眠 ...

  3. Ubuntu16.04安装配置和使用ctags

    Ubuntu16.04安装配置和使用ctags by ChrisZZ ctags可以用于在vim中的函数定义跳转.在ubuntu16.04下默认提供的ctags是很老很旧的ctags,快要发霉的版本( ...

  4. python内置的魔术命令(builtin magic commands)

    在ipython或者jupyter notebook中,会出现"%"开头并且一个很短的命令,例如交互式的matlablib绘图: %matplotlib inline 之前一直不知 ...

  5. RabbitMq相关运维

    # 命令查询所有用户列表rabbitmqctl list_users # 使用命令对 xiandian-admin 用户进行授权set_permissions xiandian-admin '.*' ...

  6. SVG 图像入门教程

    http://www.ruanyifeng.com/blog/2018/08/svg.html 一.概述 SVG 是一种基于 XML 语法的图像格式,全称是可缩放矢量图(Scalable Vector ...

  7. 【AtCoder】ARC077

    C - pushpush 如果是按下标说的话 如果是偶数个 那么是 \(N,N - 2,N - 4...1,3,5...N - 1\) 如果是奇数个 \(N,N - 2,N - 4...2,4,6.. ...

  8. k8s 相关命令

    kompose convert -f docker-compose-pro.yml k8s数据卷挂载: https://blog.csdn.net/wlhdo71920145/article/deta ...

  9. UOJ#191. 【集训队互测2016】Unknown 点分治 分治 整体二分 凸包 计算几何

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ191.html 题目传送门 - UOJ191 题意 自行移步集训队论文2016中罗哲正的论文. 题解 自行 ...

  10. 存储过程导入excel

    #region 导入订单        protected override string DoExcelData(System.Data.DataTable dt)        {         ...