linux - Bash:为什么我不能为变量分配绝对路径?

标签 linux bash shell

我正在尝试为 Bash 中的变量分配绝对路径:

#!/bin/bash
DIR= "/home/foobar"

echo "$DIR/test"

输出:

./test.sh: line 2: /home/foobar: Is a directory
/test

我不明白那里发生了什么,请帮助我。

最佳答案

去掉"/home/foobar"前的空格:

#!/bin/bash
DIR="/home/foobar"

echo "$DIR/test"

关于linux - Bash:为什么我不能为变量分配绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26540352/

相关文章:

linux - 使用 Wget 获取长 URL

linux - 使用 sed/awk 命令找到模式后修改文本文件的内容

bash - 具有 OPML 支持的 RSSTail 替代方案?

bash - 在 bash 中比较 PID

linux - 如何从第二行使用 awk '{print $1*Number}' 或告诉他忽略 NaN 值?

bash - Grep 仅在匹配后打印

python - 使用curl获取csv的shell脚本

linux - 在 Linux 中使用 unzip 时遇到问题

linux - 中断 : Node Process was killed by signal 6 (SIGABRT)

linux - Centos 5.8 上的 iotop - OSError : Netlink error: Invalid argument (22)