我在/usr/bin
. 让我们称之为hello
。
它包含以下内容:
echo "I am located in $PWD"
echo "I am called from this directory: ???"
Run Code Online (Sandbox Code Playgroud)
hello
从/home/Documents
我期望以下输出运行:
echo "I am located in $PWD"
echo "I am called from this directory: ???"
Run Code Online (Sandbox Code Playgroud)
如何获取运行脚本的目录路径?
我有一个脚本来检查一个文件是否存在于 tar 文件中,但出了点问题,因为它总是转到else
脚本的一部分。我很确定它不应该是那样的。
日期采用“Mon dd”格式(1 月 11 日)。
echo "enter date: \c"
read date
tarfile=`tar -tvf tarfile.tar | grep some_file | grep "$date"`
if [ -f "$tarfile" ]; then
echo "yes"
else
echo "no"
fi
Run Code Online (Sandbox Code Playgroud)