per*_*sec 5 bash shell-script quoting command-substitution
首先,我写了一个配置文件,其中包含我所有的参数,如下所示
path="/home/test/"
Run Code Online (Sandbox Code Playgroud)
我的名字test.conf
。
然后我用这个内容编写一个 shell 脚本,命名它test
,并用chmod +x
.
#!/bin/bash
#read the config file
. /home/test/test.conf
#cat the file /home/test/test
cat `$path`test #This line is the problem
Run Code Online (Sandbox Code Playgroud)
我得到这个输出
./test/test: line 3: /home/test/: Is a directory
cat: test: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我想要的是它向我显示文件的内容/home/test/test
。
如何正确编写此脚本,使其不会在文件路径后换行?