0

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}
cmak.fr
  • 8,976

3 Answers3

1

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.

Elder Geek
  • 36,752
0

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}"
cmak.fr
  • 8,976
0

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.txt
foo$ cat /tmp/${line}
Hello World
foo$ 
jason120
  • 106