I am storing a file path in a file and need to pass the contents of that file as an argument to a shell script, specifically Maven, something like so:
mvn -Dvar_name=(contents of file)
Would this work:
mvn -Dvar_name=(cat /path/to/file)
?
|
|
|
This can be done using command substitution, like so:
This has a notable caveat, though, namely that all trailing newlines are stripped. If that doesn't matter, though, then that should work. If you really just want to read one line, you could use
|
|||
|
|
|
For command substitution, you need to use It is also important that you quote the substitution, or it will expand into multiple arguments if the file contains more than one word. Here are some examples:
|
|||
|
|