diff options
author | Thalia Archibald <thalia@archibald.dev> | 2024-11-01 00:10:30 -0700 |
---|---|---|
committer | Emanuele Torre <torreemanuele6@gmail.com> | 2024-11-08 19:07:55 +0100 |
commit | 7a1fd72d2d3fd6593018aacea9288de450400e79 (patch) | |
tree | 2d42ffc55cd8b75a28955cf18b5826d86dbbf8ae | |
parent | 0558e77e8c0cc4c6250ebddd1cddcb63bbf33615 (diff) |
Fix missing program from file
When jq is not supplied with a program, it usually exits with an error
and usage text, except for when jq is not connected to a TTY (i.e., not
interactive), in which case a default program of `.` is used. Combined
with `-f`, it then tries to read `.` as the filename.
$ jq
jq - commandline JSON processor [version 1.7.1]
…
$ jq -f
jq - commandline JSON processor [version 1.7.1]
…
$ jq | cat
^C
$ jq -f | cat
jq: Could not open .: It's a directory
-rw-r--r-- | src/main.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -587,7 +587,7 @@ int main(int argc, char* argv[]) { jq_set_attr(jq, jv_string("VERSION_DIR"), jv_string_fmt("%.*s-master", (int)(strchr(JQ_VERSION, '-') - JQ_VERSION), JQ_VERSION)); #ifdef USE_ISATTY - if (!program && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO))) + if (!program && !(options & FROM_FILE) && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO))) program = "."; #endif |