• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > shell中函数的应用

shell中函数的应用

作者:mdxy-dxy 字体:[增加 减小] 来源:互联网

mdxy-dxy 通过本文主要向大家介绍了vb中shell函数,shell中的函数,shell脚本中的函数,shell中调用函数,vb shell函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

To turn the functions in this chapter into a library for use in other scripts, extract all the functions and concatenate them into one big file. If we call this file library.sh, a test script that accesses all of the functions might look like this:

#!/bin/sh

# Library test script
. library.sh
initializeANSI

echon "First off, do you have echo in your path? (1=yes, 2=no) "
read answer
while ! validint $answer 1 2 ; do
 echon "${boldon}Try again${boldoff}. Do you have echo "
 echon "in your path? (1=yes, 2=no) "
 read answer
done

if ! checkForCmdInPath "echo" ; then
 echo "Nope, can't find the echo command."
else
 echo "The echo command is in the PATH."
fi

echo ""
echon "Enter a year you think might be a leap year: "
read year

while ! validint $year 1 9999 ; do
 echon "Please enter a year in the ${boldon}correct${boldoff} format: "
 read year
done

if isLeapYear $year ; then
 echo "${greenf}You're right! $year was a leap year.${reset}"
else
 echo "${redf}Nope, that's not a leap year.${reset}"
fi

exit 0
</div>

应用函数,我们就可以复用我们的脚本。

值得注意的是 $ . tinyscript.sh ,就是在当前shell下执行脚本,不加"."或source

则会在子shell下执行脚本,可能会有不同的情况发生,值得注意。

</div>

您可能想查找下面的文章:

  • shell中函数的应用

相关文章

  • linux shell数组深入学习理解
  • Linux Shell简介
  • Shell脚本批量重命名文件后缀的3种实现
  • linux删除大量文件的6种方法
  • expect实现单台、多台服务器批量scp传输文件
  • linux命令详解之useradd命令使用方法
  • Shell 函数参数
  • Linux下统计当前文件夹下的文件个数、目录个数
  • 如何使用微博自动记录俯卧撑个数
  • shell基础学习中的字符串操作、for循环语句示例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Ubuntu配置NFS的具体流程(推荐)
    • 对用户输入的判断的shell实现代码
    • linux下python3连接mysql数据库问题
    • CCKiller:Linux轻量级CC攻击防御工具,秒级检查、自动拉黑和释放
    • Linux更新Python版本及修改python默认版本的方法
    • 两个备份数据库的shell脚本
    • 通过短信发送LOG归类号码发送情况的shell脚本
    • Linux/Nginx如何查看搜索引擎蜘蛛爬虫的行为
    • linux shell命令执行顺序的控制方法
    • Linux Shell中三种引号的用法及区别

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有