Re: Fwd: Clearing RAM Caches
On Tue, Aug 16, 2022 at 08:25:12AM +0100, Tixy wrote:
> On Mon, 2022-08-15 at 21:05 -0400, Timothy M Butterworth wrote:
> > >
> > Thanks for the clarification. `echo 1 > sudo /proc/sys/vm/drop_caches`
> > seems to work just fine.
>
> It doesn't, as Tomas pointed out it creates a file called 'sudo' and
> puts a '1' in it.
The following two commands are equivalent:
echo 1 > sudo /proc/sys/vm/drop_caches
echo 1 /proc/sys/vm/drop_caches > sudo
The file "sudo" will have "1 /proc/sys/vm/drop_caches" in it, because
echo received two arguments. Redirections may appear anywhere in a
"simple" command. It's conventional to write them at the end of the
command, but the shell permits them to be anywhere.
This is a standard feature of all POSIX shells, by the way. Not a
bash extension.
Redirections must appear at the end of "compound" commands, which are
basically anything with internal shell syntax -- if, case, while, and
so on. It may be desirable to try to write something like:
< inputfile while read -r line; do
...
done
but it's not allowed. You have to write it as:
while read -r line; do
...
done < inputfile
Or, explicitly open the input file on a new FD (file descriptor), and
close it afterward:
exec 3< inputfile
while read -r line <&3; do
...
done
exec 3<&-
Reply to: