Skip to main content
18 events
when toggle format what by license comment
Jun 30 at 20:20 comment added Seamus +1 for printf "%s" "$(<filename)"... it may not be needed (may not even work) for zsh, but I am not a frequent zsh user.
Jun 30 at 20:18 history edited Seamus CC BY-SA 4.0
improve *accuracy* of answer
Jul 3, 2023 at 6:32 comment added user167612 Be very careful with <filename. A simple mistake of writing >filename instead can destroy your file!
Jul 3, 2023 at 6:28 comment added Stéphane Chazelas @jarno, < filename works in zsh where it does $READNULLCMD < filename, $READNULLCMD being a pager by default.
Jul 3, 2023 at 6:26 comment added Stéphane Chazelas cat's primarily use is to concatenate, but among all the commands that can dump the contents of a file, it's one of the rare ones that doesn't modify it in the process. Your $(...) removes trailing newline characters, in bash removes the NULs, echo does further modifications if there are backslashes or it starts with -. In bash, that still forks a process and the contents has to be fed through a pipe and stored whole several times in memory. Really not an improvement over cat file.
Dec 11, 2022 at 12:01 comment added EsmaeelE Fun fact: use echo without double quote echo $(<filename) print files without new lines. write file contents in one line on standard output.
Sep 24, 2022 at 19:21 comment added t7e I've tested, < filename only works on zsh and not on GNU bash version 5.1.16(1)-release.
Aug 22, 2022 at 11:36 comment added pmor @jarno Why bare < filename does not display contents of the file?
Sep 25, 2018 at 5:52 comment added Saman Bayat That's great idea for using Linux Internal Command with echo "$(<filename)". Thanks ...
Jan 11, 2018 at 8:13 comment added Yokai +1 for the echo "$(<filename)" bashism. Not enough of that here.
Jan 2, 2018 at 12:07 history edited Jeff Schaller CC BY-SA 3.0
missing apostrophe
Jun 21, 2017 at 20:42 comment added jarno You could use tee < filename, too.
Jun 21, 2017 at 19:57 comment added jarno Bare < filename does not display contents of the file, but cat filename does.
Sep 29, 2015 at 20:21 comment added X Tian Your update: "< filename is exactly what you want, ..." is misleading. Overall, although this is an interesting discussion on alternatives, I think cat is simpler.
Sep 29, 2015 at 19:17 review Late answers
Sep 29, 2015 at 20:21
Apr 20, 2015 at 8:14 history edited crunsher CC BY-SA 3.0
added 89 characters in body
Apr 10, 2015 at 13:39 review First posts
Apr 10, 2015 at 13:41
Apr 10, 2015 at 13:35 history answered crunsher CC BY-SA 3.0