4 ms·
Given the proximity of `<` and `>`, and the fact that `> somefile.txt` will silently truncate the file, I would take issue with the "safeness" claim :P Also, `
by cgs1019 14y ago
Given the proximity of `<` and `>`, and the fact that `> somefile.txt` will silently truncate the file, I would take issue with the "safeness" claim :P
Also, `< file.txt | wc` doesn't work (at least not in bash; zsh (my install/plugin combo, at least) apparently tries to map the lone `< file.txt` to `less -R file.txt`...which spits out an error. Anyway, omitting the pipe will work: `< file.txt wc -l`
`cat` by definition concatenates one or more files and spits the output to stdout, so using it on a single file is perfectly within the bounds of its definition (IMHO; I realize people get really zealous about this type of thing and I'm not trying to start a war).
- pwg 14y ago> and the fact that `> somefile.txt` will silently truncate the file Bash has the "set -C" option to toggle on "no-overwrite" mode for redirection operators.
- Evbn 14y agoBut it's obnoxiously not set by default.
- deleted 14y ago[deleted]
- sequoia 14y agoThis might screw up some POSIX shell scripts if they expect to be able to write a tmp file or overwrite one if it already exists.
- gnosis 14y agozsh also has a "setopt NO_CLOBBER", but it's also not the default (unfortunately). Default behavior: % touch foo % echo bar > foo % cat foo bar % rm foo No clobber mode: % setopt NO_CLOBBER % touch foo % echo bar > foo zsh: file exists: foo Manual override: % echo bar >| foo % cat foo bar
- Evbn 14y agoCat catenates, it doesn't nearly always concatenate :-)