Skip to content

Commit

Permalink
Fix order of -- and - in cat command
Browse files Browse the repository at this point in the history
Somewhat unintuitively, the "-" is considered to be a file operand
and not an option, even though it treated to signify standard input
rather than a file named "-". On some systems including macOS,
options to cat cannot follow paths. On those systems, writing "-"
before "--" causes "--" to be treated as a filename, causing the
script to break on macOS.

This changes the order, which lets the cat command work on all
systems, though (as before) if the subsequent argument were a
literal "-" then that would not have the desired effect. In this
case that is okay, since we actually know that the other argument,
the value of the source_file variable, is not exactly "-".

(We even know that it does not begin "-". But keeping the "--"
before it makes clearer to human readers that this argument is a
path and never an option.)
  • Loading branch information
EliahKagan committed Apr 9, 2024
1 parent 97abf7f commit 7c45adf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion etc/copy-packetline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function copy_with_header () {
fi

make_header "$source_file" "$endline" |
cat - -- "$source_file" >"$target_file"
cat -- - "$source_file" >"$target_file"
}

function generate_one () {
Expand Down

0 comments on commit 7c45adf

Please sign in to comment.