Shell编程有系统函数,也可以自定义函数。

系统函数 

basename  指令

功能:返回完整路径最后 / 的部分,常用于获取文件名  如,/home/文档/demo.txt  可获取demo.txt

基本语法:

basename [pathname] [suffix]

basename [string] [suffix]

(功能描述:basename命令会删掉所有的前缀包括最后一个(‘/’) 字符,然后将字符串显示出来。

选项: suffix为后缀,如果suffix被指定了,basename会将pathnamestring中的suffix去掉。

Linux Shell 函数

 dirname 指令

功能与basename正好相反,如果basename是获取文件名,则dirname 用于获取目录。

Linux Shell 函数

 

自定义函数 

 

基本语法

function  funname(){

Action;

[return int;]

}

funname []

直接看不好看直接上代码

Linux Shell 函数

补充 $? 代表最后程序的返回值。

Linux Shell 函数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-11-03
  • 2022-01-22
  • 2022-02-10
  • 2022-02-10
猜你喜欢
  • 2021-05-18
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-08-05
相关资源
相似解决方案