当前位置:网站首页>Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH
2022-08-09 10:29:00 【Mary Soda Meatloaf】
#!/bin/bash#inpathin_path(){cmd=$1 ourpath=$2 result=1 #1oldIFS=$IFS IFS=":" #2for directory in $ourpathdoif [ -x $directory/$cmd ]; then #3result=0fidoneIFS=$oldIFSreturn $result}checkForCmdInpath(){var=$1if [ "$var" != "" ];thenif [ "${var:0:1}" = "/" ];then #4if [ ! -x $var ];thenreturn 1fielif ! in_path $var "$PATH";thenreturn 2;fifi}checkForCmdInpath "$1"case $? in0) echo "$1 found in PATH" ;;1) echo "$1 not found or not executable" ;;2) echo "$1 not found in PATH" ;;esacexit 01:Default variables for shell scripts
$# is the number of arguments passed to the script
$0 is the name of the script itself
$1 is the first argument passed to the shell script
$2 is the second argument passed to the shell scriptparameters
[email protected] is a list of all parameters passed to the script
$* is a single string showing all parameters passed to the script, unlike positional variables, the parameters can be more than 9
$$is the current process ID number of the script running
$? is the exit status of the last command, 0 means no error, other means there is an error
sh test.sh opt1 opt2 opt3 opt4$0 $1 $2 $3 $42:IFS separator
https://zhuanlan.zhihu.com/p/36513249
3: Judgment symbol [ ]
Each component in'[ ]' needs to be separated by spaces.Variables are best surrounded by quotes.
Check file permissions
-r Whether the file exists, and the readable permission
Whether the -w file exists, and the writable permission
Whether the -x file exists, and the executable permission
Whether the -u file exists, and hasSUID attribute
-g Whether the file exists and has the SGID attribute
Whether the file exists and has the Sticky bit attribute
-s Whether the file exists and is a non-blank file
4: Variable segmentation syntax, starting from the offset, truncating according to the given length (if no length is provided, the rest of the string will be returned)

Script 1 running result

边栏推荐
- Unix Environment Programming Chapter 14 14.8 Memory Mapped I/O
- Unix Environment Programming Chapter 15 15.7 Message Queuing
- 深度学习--循环神经网络(Recurrent Neural Network)
- 【Linux】宝塔面板设置MySQL慢查询日志,未走索引日志
- WUSTOJ:n个素数构成等差数列
- 想了解API接口,这一篇就够了
- 在犹豫中度过了老多天,今天的工作时记录
- 元组 字典 集合
- 工作--今天的学习
- Battery modeling, analysis and optimization (Matlab code implementation)
猜你喜欢
随机推荐
深度学习--神经网络(基础讲解)
Technology Sharing | Sending Requests Using cURL
[贴装专题] 视觉贴装平台与贴装流程介绍
Collections and Functions
京东物流与五菱将开发联名版定制产品
1004 成绩排名 (20 分)
StratoVirt 中的虚拟网卡是如何实现的?
【原创】JPA中@PrePersist和@PreUpdate的用法
Tom Morgan | Twenty-One Rules of Life
想了解API接口,这一篇就够了
The GNU Privacy Guard
LM小型可编程控制器软件(基于CoDeSys)笔记二十六:plc的数据存储区(模拟量输入通道部分)
收到人生第一笔五位数工资
[贴装专题] 贴装流程中涉及到的位置关系计算
面试官:MySQL 中 update 更新,数据与原数据相同时会执行吗?大部分人答不上来!
学习NET-SNMP之二-----------VisualStudio编译Net-SNMP
主从postition变化无法锁定_Slave_IO_Running显示No_Slave_Sql_Running显示No---Mysql主从复制同步002
function two
Restful WebServices 学习笔记
相伴成长,彼此成就 用友U9 cloud做好制造业数智化升级的同路人



![[贴装专题] 贴装流程中涉及到的位置关系计算](/img/72/a60a51c86e641749f38fab66f1236a.png)

![[贴装专题] 基于多目视觉的手眼标定](/img/10/8303854fbba5d9b06032e38e9df233.png)

![[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目](/img/e9/d41f144a2f27e76f97cd6401d37578.png)

![[Halcon&定位] 解决Roi区域外的模板匹配成功](/img/ad/549c7e6336ef62469a7c71e6bfcb42.png)