先上代码:
#!/bin/bash
#date:20181129
#author:cxpath=`cd $(dirname $0);pwd -P`
echo the current path is:$path
for i in `ls`
do
echo $i
done
filename=`basename $0`
echo file name is:$filename
运行效果:
[tony@localhost script]$ sh getpwd.sh
the current path is:/home/tony/Desktop/script
fuzubaoyou.sh
getpwd.sh
grade.txt
jindutiao.sh
substring.sh
file name is:getpwd.sh
全路径:path=`cd $(dirname $0);pwd -P`
echo the current path is:$path
遍历当前目录下所有文件:
for i in `ls`
do
echo $i
done
当前文件脚本名:`basename $0`