Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 with 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

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?

share|improve this question
    
You should use double quotes ("$path"), not backquotes. –  enzotib Jan 12 '12 at 9:36
add comment

1 Answer

up vote 7 down vote accepted

`` 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.