当前位置:网站首页>Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function
Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function
2022-07-27 10:05:00 【Redamancy06】
List of articles
1. function
1.1 System function
1.1.1basename
1.1.1.1 Basic grammar
basename [string / pathname] [suffix] ( Function description :basename The command will delete all prefixes including the last (‘/’) character , Then display the string .
basename It can be understood as taking the file name in the path
Options :
suffix For the suffix , If suffix Designated ,basename Will pathname or string Medium suffix Get rid of .
1.1.2dirname
dirname File absolute path ( Function description : Remove filename from given filename with absolute path ( Non catalog part ), Then return to the rest of the path ( Part of the catalog ))
dirname It can be understood as the absolute path name of the file path
1.1.3 Case study
1.1.3.1date+%s Timestamp exercise



1.1.3.2basename The practice of

Cut out the file name 
parameter File code 
The displayed file name includes the path , We don't need the output path , So add basename To solve


1.1.3.3dirname The practice of
dirname Intercept the path before the last slash , Do not include filename
and basename Intercept the file name after the last slash , Exclude path



If only pwd Words , Executing code in other folders will not print the directory of the script , Need to add dirname, as follows 

add dirname The script path after output remains unchanged
1.2 Custom function
1.2.1 Basic grammar
[ function ] funname[()]
{
Action;
[return int;]
}
1.2.2 Experience and skill
(1) Must be before calling function place , Declare function first ,shell The script is run line by line . It doesn't compile first like any other language .
(2) Function return value , Only through $? System variable acquisition , Can display plus :return return , If not , Results will be run with the last command , As return value .return Heel value n(0-255)
1.2.3 Case study
1.2.3.1 Not used return Version of



Can output and
1.2.3.2 use return If you come back


It can be seen that ,return It must be followed by a number , Revised as follows :

In this way, the results can be output normally , however return Can only return 0-255, If the number exceeds, the correct answer cannot be displayed , as follows 
156+245!=145 Of , So it can explain return Only return 0-255 Number of numbers , How can we solve this problem , Look at the code below 
In this way, the function add Inside echo The value is assigned to ans, And then output 
The result is also right , Explain that this is correct
边栏推荐
- LeetCode.1260. 二维网格迁移____原地暴力 / 降维+循环数组直接定位
- Anchor free detector: centernet
- 食品安全 | 无糖是真的没有糖吗?这些真相要知道
- Understand chisel language. 25. Advanced input signal processing of chisel (I) -- asynchronous input and de jitter
- Shell的read 读取控制台输入、read的使用
- Leetcode.814. binary tree pruning____ DFS
- Summary of engineering material knowledge points (full)
- I haven't delivered books for a long time, and I feel uncomfortable all over
- NFT系统开发-教程
- Expose a technology boss from a poor family
猜你喜欢

省应急管理厅:广州可争取推广幼儿应急安全宣教经验

Concurrent thread state transition

WGAN、WGAN-GP、BigGAN

吃透Chisel语言.25.Chisel进阶之输入信号处理(一)——异步输入与去抖动

超赞的卡尔曼滤波详解文章

Food safety | the kitchen board environment is very important. Do you know these use details?

卸载CUDA11.1
![[SCM]源码管理 - perforce 分支的锁定](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[SCM]源码管理 - perforce 分支的锁定

食品安全 | 无糖是真的没有糖吗?这些真相要知道

Acl2021 best paper released, from ByteDance
随机推荐
Final examination paper of engineering materials
语音直播系统——开发推送通知需要遵守的原则
Nacos configuration center dynamically refreshes the data source
Interview Essentials: shrimp skin server 15 consecutive questions
3D人脸重建:Joint 3D Face Reconstruction and Dense Alignment with position Map Regression Network
如何在树莓派上安装cpolar内网穿透
Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
Anaconda安装(非常详细)
Excellent Kalman filter detailed article
Go Basics - arrays and slices
习题 --- 快排、归并、浮点数二分
Concurrent thread state transition
一骑入秦川——浅聊Beego AutoRouter是如何工作
Review of in vivo detection
Engineering survey simulation volume a
会议OA项目之会议排座功能&&会议送审的实现
What happens if the MySQL disk is full? I really met you!
去 OPPO 面试,被问麻了
Summary of binary tree exercises
Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量