Bash: Merge foldername from variable with filename
33,950
``
and $()
is used for command execution, not for substituting it for variable content. So bash tries to execute varaible meaning in ``
and returns the error that it is a directory.
Just write cat ${path}test
and it will work in the way you want.
For more information read about bash variables and command substitution.
Related videos on Youtube
Author by
persec
Updated on September 18, 2022Comments
-
persec over 1 year
First I write a configfile with all my parameters like this
path="/home/test/"
I name it
test.conf
.Then I write a shell script with this content, name it
test
, and make it executable withchmod +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
I get this output
./test/test: line 3: /home/test/: Is a directory cat: test: No such file or directory
What I would like is that it shows me the content of the file
/home/test/test
.How do I write this script correctly, so that it doesn't make a new line after the file path?
-
enzotib over 12 yearsYou should use double quotes (
"$path"
), not backquotes.
-