所以我一直在开始编写 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/
这可能是一个简单的修复,但我不知道如何修复它。