shell 如何让脚本识别文件路径?[副本]

4dc9hkyq  于 2023-08-07  发布在  Shell
关注(0)|答案(1)|浏览(107)

此问题在此处已有答案

How to manually expand a special variable (ex: ~ tilde) in bash(19个答案)
7天前关闭
因此,我正在制作一个简单的脚本,用于将多个文件移动到新位置。我只想问问那些文件去哪了。所以我输入了

~/i/want/to/go/here

字符串
提示后。
脚本似乎不能将其视为有效,即使我从命令行直接复制并传递。
我试过$location周围的引号,双引号,提示后的空格,多次检查我的文件路径,直接复制粘贴我的路径。
当它说它正在检查路径时,它说得很好,但它似乎无法验证它是否存在。

I=INCAR
K=KPOINTS
o=openmpiscript
P=POSCAR
s=submit.vasp

echo "we are going to move INCAR,KPOINTS,openmpiscript,POSCAR, and submit.vasp to a desired location"
echo "Just tell me where to put them and I will automatically move all those files on your behalf."
read -p "location please:" location

echo "ok we can check and see whether or not $location is a real place"

if [[ -d $location ]];
then
    echo "yup, $location is there"
else
    echo "hmmm, this might not be a working directory path"
    exit 1
fi


哦,我列出了我上面尝试过的,但基本上我尝试了引号,没有引号,调整我的路径,通过使用cd来验证我的路径,然后复制粘贴。
结果是它退出,因为它不认为该路径是有效的,它看不到该目录,即使它在那里。

6l7fqoea

6l7fqoea1#

请按照链接到重复的问题。
它不起作用的原因:bash在 * 扩展变量之前扩展 *。然后它不会回到第二轮扩张。
请注意https://www.gnu.org/software/bash/manual/bash.html#Shell-Expansions中展开的顺序

相关问题