0

How is possible that 'delta_oligo_combined.bedgraph' file is in the directory and can't be seen by cat command? OSX typo?

$ type=oligo
$ file_type=combined
$ ls delta_oligo_combined.bedgraph
delta_oligo_combined.bedgraph
$ cat delta_$(type)_$(file_type).bedgraph
-bash: file_type: command not found
cat: delta__.bedgraph: No such file or directory
mklement0
  • 382,024
  • 64
  • 607
  • 775
biotech
  • 697
  • 1
  • 7
  • 17

1 Answers1

1

You're looking to include variable values in a (path) string:

  • ${varName} is how you reference a variable named varName - note the delimiters, { and } (which aren't always needed).

  • By contrast, you mistakenly used syntax $(...), which is meant for for embedding the output from commands in a string.

    • Therefore, tokens type and file_type were interpreted as commands and executed:

      • type happens to be the name of a builtin utility that outputs nothing when called without parameters.

      • file_type, on the other hand, is not the name of any existing command, which is why Bash complained (command not found).

    • The resulting file path - after the command substitutions were performed - was delta__.bedgraph (both command substitutions expanded to the empty string), causing cat to report a non-existent file (No such file or directory).

See man bash for more.

mklement0
  • 382,024
  • 64
  • 607
  • 775