I want to cat or read the contents of file giving absolute path that contains a variable but its not working..

None of the below commands are working.
($line here is the name of file)

content=`(cat /tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/${line})`

cat '/tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/'${line}
  • "None of the below commands are working." I recommend you edit this question with details about what does happen when you run those commands, including complete exact output. If that doesn't show the actual name of at least one one of the files for which it fails, please include that, too. – Eliah Kagan Jul 21 at 4:53
  • 1
    An example of what $line contains would be helpful. Maybe it already contains the directory name? Maybe it contains spaces? We simply do not know enough to help. – WinEunuuchs2Unix Jul 21 at 18:12
  • Close voters. Crafting answer. – Elder Geek Jul 22 at 13:54

Variable assignation from cat:

content=$(cat /tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/${line})
# Or
content=`cat /tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/${line}`

cat a file from variable:

cat /tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/${line}
# OR
cat "/tmp/cygwin/cygwin/home/67642360/1.0.94/db/src/sql/oracle/updates/${line}"

What is ${line}?

Can you try echo ${line}?

What shell are you using? You can set line to be a valid file name. I'm using bash in this example.

foo$ echo ${line}

foo$ echo "Hello World" > /tmp/foo.txt 
foo$ export line=foo.txt
foo$ echo ${line}
foo$ cat /tmp/${line}
Hello World

If as you say $line contains the name of the file you wish to output , you can simply cat (or more or less) the variable. as in cat $line

A safer method that would work even if the filename includes spaces would be cat "$line"

You should insure that you know the difference between full and relative paths as you aren't likely to get the results you want if you confuse the two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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