这篇文章给大家介绍如何在shell中使用函数,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。#!/bin/sh# Library test script. library.shin
这篇文章给大家介绍如何在shell中使用函数,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
#!/bin/sh# Library test script. library.shinitializeANSIechon "First off, do you have echo in your path? (1=yes, 2=no) "read answerwhile ! validint $answer 1 2 ; do echon "${boldon}Try again${boldoff}. Do you have echo " echon "in your path? (1=yes, 2=no) " read answerdoneif ! checkForCmdInPath "echo" ; then echo "Nope, can't find the echo command."else echo "The echo command is in the PATH."fiecho ""echon "Enter a year you think might be a leap year: "read yearwhile ! validint $year 1 9999 ; do echon "Please enter a year in the ${boldon}correct${boldoff} fORMat: " read yeardoneif 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}"fiexit 0
应用函数,我们就可以复用我们的脚本。
值得注意的是 $ . tinyscript.sh ,就是在当前shell下执行脚本,不加"."或source
则会在子shell下执行脚本,可能会有不同的情况发生,值得注意。
关于如何在shell中使用函数就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
--结束END--
本文标题: 如何在shell中使用函数
本文链接: https://www.lsjlt.com/news/256962.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0