The question has been edited to include a log of the problem being introduced, which includes the command:
# Taken from edited question
$ echo 'hello' > sudo tee /data/hello
In bash (which allows redirection operators at any point in a simple command), this is precisely equivalent to running:
# From question, with redirection moved to end to make actual behavior more readable
echo 'hello' tee /data/hello > sudo
That is, it's creating a file named sudo
in your current directory, not using sudo
to run tee
(in the above, tee
is just an argument to echo
).
What you want, by contrast, is:
# CORRECT: Using a pipe, not a redirection
echo 'hello' | sudo tee /data/hello
with a pipe (|
) rather than a >
.
tee
should create the destination file for you. – Attie Mar 15 '17 at 13:23/etc
that would explain it, but this seems unreproducible on any reasonably regular system. – tripleee Mar 15 '17 at 13:26sudo tee /etc/some/file
, and/etc/some
didn't exist, that would have the behavior described.sudo tee /etc/file
, by contrast, is a completely legitimate way to escalate privileges used to write to/etc/file
. I'd suggest reproducing the issue withset -x
enabled, and incorporating that exact, unedited log into the question. – Charles Duffy Mar 15 '17 at 13:44