I have a file named "-diary.txt-", I need to get it's content. When trying to read it using echo < "-diary.txt-"
, it returns a blank string. I did some research, and came up with this: echo "$(<-diary.txt-)"
. I tested it out on my computer, and it worked perfectly, but when I logged on the server, it still returns a blank string. I can only use these commands:
. : [ [[ alias bg break cd chdir command continue echo eval exec exit export false fg getopts hash help history jobs kill let local printf pwd read readonly return set shift source test times trap true type ulimit umask unalias unset wait
. What should I do?

- 13
1 Answers
$(<file)
is a special construct of the Korn shell now also supported by a few others including zsh
and bash
, but that's about it (see Understanding Bash's Read-a-File Command Substitution).
On POSIX-like shells that don't support it, that would just expand to nothing.
Among your list of commands, only read
seems to be able to read
input in a useful way¹. echo
doesn't read anything, it just outputs its arguments after option processing and transformation.
while IFS= read -r line || [ -n "$file" ]; do
printf '%s\n' "$line"
done < -diary.txt-
Should read the contents one line at a time and print each line with printf
(not echo
which can't be used for arbitrary data). All three commands used there ([
, read
and printf
) are in your list, the while; do; done
and ||
are language constructs of the shell.
That should work as long as the file doesn't contain NUL characters. If the file didn't end in a newline character, that will add it on output.
That assumes the shell is POSIX-sh-like, but given that list of commands, many of which are typically sh
builtins, that's more than likely.
¹, .
aka source
can also read files, but it also tries to interpret what it reads as shell code, so that won't be useful.

- 544,893