如何解决一种存储/ home / $ USER进行测试的方法
我是shell脚本的新手,我不希望用户在运行程序时不必键入目录的完整路径。
#!/bin/bash
# Tests the directory,if there is a return
#XXX I want to prevent the user from entering
# the entire path /home/$USER
echo "Enter search directory: "
read dir
if test -d "$dir"
then
echo "Found directory: $dir"
else
echo "Directory not found!"
fi
执行示例:
> ./dir
>> Enter the directory:
>>> /home/$USER/Downloads
>>>> Directory Found: /home/user/Downloads
我想要什么:
> ./dir
>> Enter the directory:
>>> Downloads
>>>> Directory Found: /home/user/Downloads
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。