linux - 无法将读取输入传递到 cat 路径

标签 linux bash shell scripting

这里是 bash 新手。我正在尝试将读取输入传递到 cat 命令的文件路径。

read -p "enter folder" folderid
read -p "enter port (optional)if not required press 0:" port
if [$folderid -ne 0 && $port -ne 0];then
  new_interface=$(cat /var/abc/def/xyz_$fileid/randomfile)
  echo "$new_interface"
fi

folderid 的示例输入:134567

我收到一条错误消息:

-bash: [134567: command not found

不确定我做错了什么,尝试了不同的方法似乎没有效果。

最佳答案

shell 的分词器对空格敏感。单词在空格和特殊字符处分割,例如 ;&&& 等。使用

if [ $folderid -ne 0 -a $port -ne 0 ]; then

关于linux - 无法将读取输入传递到 cat 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41347361/

相关文章:

linux - riscv/gcc/ld - "Undefined reference to printf"使用自己的脚本链接

regex - 我在 Linux 中使用带有正则表达式的 sed 但没有得到预期的答案

c - Linux 消息队列的接收端应该放什么键?

linux - 如何在 bash 中使用 $find 命令抑制文件夹排序

bash - 我可以在命令之间进行管道传输,并从不同的目录运行程序吗?

shell - 如何知道有多少进程正在运行?

linux - 如何在 shell 脚本中使用 curl?

linux - Bash 脚本多字符串变量比较

linux - tar 创建一个空文件夹,我该如何摆脱它?

linux - 将目录更改为尾部结果路径的 shell 脚本