【发布时间】:2016-11-04 11:13:54
【问题描述】:
所以我一直在开始编写 bash 脚本,并且我正在制作一个将从源代码自动安装的脚本(因此它基本上只是为您编译 tarball)。我需要它来更改目录才能进入压缩包。但是,每当我使用此命令时
read path
cd $path
我总是收到错误tar-installer.sh: line 13: cd: ~: No such file or directory
对于任何需要它的人,这是完整的脚本...
#!/bin/bash
# This program auto-installs tarballs for you.
# I designed this for Linux noobies who don't
# know how to install tarballs. Or, it's for
# people like me who are just lazy, and don't
# want to put in the commands ourselves.
echo "Tar Installer v1.1"
echo "Gnu GPL v2.1"
echo -n "Path to tarball:"
read path
cd $path
echo -n "Please enter the file you wish to complile..."
read file
if $file =="*.tar.gz"
then
tar -xzf $file
else
$file =="*.tgz"
then
tar -xzf $file
else
$file =="*.tar.bz2"
then
tar -xjf $file
包含 tarball 的最后一部分仍在进行中。但是我用于cd path 的目录是~/Downloads/
这可能是一个简单的修复,但我不知道如何修复它。
【问题讨论】:
-
在接受带有“~/”的文件路径时,问题似乎与读取内置函数有关。
-
请使用shellcheck.net 并在发布代码之前更正在那里发现的任何错误(您现在应该这样做)。谢谢,祝你好运..