【Linux】善用判断式---test

简介: 【Linux】善用判断式---test

1 .使用test指令

(1)检测文件是否存在时test指令是特别好用的

image.png

参数大全:

屏幕快照 2022-05-18 下午3.35.44.png2. test指令案例


1. 这个文件是否存在,若不存在则给予一个“Filename does not exist”的讯息,并中断程


序;


2. 若这个文件存在,则判断他是个文件或目录,结果输出“Filename is regular file”或


“Filename is directory”


3. 判断一下,执行者的身份对这个文件或目录所拥有的权限,并输出权限数据!

image.png

测试结果

image.png

这里在简单的说一下exit 0这个指令

&&表示如果前面的命令成功执行则继续后面的命令,exit退出当前shell并且返回0,0这个返回值表示命令成功执行

相关文章
|
2月前
|
Linux Shell
在Linux中,如何显示/test目录下的所有目录?
在Linux中,如何显示/test目录下的所有目录?
|
5月前
|
人工智能 Linux Shell
linux命令-条件判断-test
linux命令-条件判断-test
26 1
|
Shell Linux Windows
Linux shell编程基础语法语句(shell变量,shell脚本语句,test测试语句)
Linux shell编程基础语法语句(shell变量,shell脚本语句,test测试语句)
111 0
|
Linux Shell
Linux Command test
Linux Command test
|
Shell Linux
test命令 ---- linux shell 脚本
test命令 ---- linux shell 脚本
128 0
|
Shell 测试技术 Linux
Linux Shell : Test命令参数解析
格式: test conditions test -n string : string 不为空 test -z string : string 为空 test int1 -eq int2  : int1 == int 2test int1 -ne int2  : int1 != int2 te...
979 0
下一篇
无影云桌面