Storing a directory as a variable for later use in linux script

In my script, I hold the location (path) of the file as a variable.

For example, fileA

An example of its contents is

fileA = / usr / other folder / somefold / "filenamehere"

However, when I invoke a command in a file in a script, for example:

cat $ fileA

or

cat "$ fileA"

I get a message that the file or directory does not exist. If I echo $ fileA to find out what the output is and then run the cat manually from the terminal, it works fine, I don’t know what is going wrong. Any help?

Some debugging info:

  • FiLea = '/ home / Jacob / Desktop / CS35L / WORK / 2 / HW / test3 / "new"
  • echo '/ home / jacob / Desktop / CS35L / WORK / 2 / hw / test3 / "new"' / Home / Jacob / Desktop / CS35L / WORK / 2 / HW / test3 / "new"
  • '[' '!' -r '/ home / jacob / Desktop / CS35L / WORK / 2 / hw / test3 / "new"' '' '

For these specific lines

Check readable file

echo $fileA if [ ! -r "$fileA" ] then o=`expr $o + 1` echo "$fileA not readable." continue fi 
+7
source share
1 answer

If the file name is new (not "new" ), change

 fileA='/home/jacob/Desktop/CS35L/WORK/2/hw/test3/"new"' 

to

 fileA=/home/jacob/Desktop/CS35L/WORK/2/hw/test3/new 
+10
source

All Articles