#!/bin/bash
#this progame is help you find a dictory or a file
#2020 5 28
echo -e 'please echo your file name \n'
read -p 'your file name :' filename
test -z $filename && echo 'you did'"'"'nt echo your filename'&& exit 0
test ! -e $filename && echo "your filename is not exit" && exit 0
test -f $filename && leixing=file
test -d $filename && leixing=dirctory
test -r $filename && quanxian=read
test -w $filename && quanxian=${quanxian}:write
test -r $filename && quanxian=${quanxian}:exeable
echo -e "$filename is a $leixing \n"
echo -e "$filename has perm is $quanxian
这是我写的区分权限的一个小脚本,下面来说一说脚本的格式
#!这个是必须有的,告诉Linux使用哪个shell来执行这个脚本,会获取相应的变量
其余#内容是自己做的注释,一般会写入时间,开源协议等等,还有历史信息,方便我们日后脚本多好区分什么什么用
相对路径绝对路径执行脚本区别
不管是相对路径还是绝对路径来执行脚本,都是在新的shell中来执行,所以说,在子shell中执行脚本所涉及的变量等等,在父shell中不会出现。
source或者 . 来执行脚本
source和. 是直接将配置导入当前shell
所以变量等等都会保存下来