Pipes and redirection are two of the most powerful functions in Linux, and I love them.
However, I'm stuck with a situation where I need to write a fixed piece of text to a file without using a pipe, redirection or a function.
I'm using Bash in case that makes a difference.
First: Why?
I'll explain why, in case there's a simpler solution.
I have a background yad notification with some menu entries. In some of the menu entries, I want the notification to write a fixed piece of text to a file. Here's an example of what I mean.
yad --notification --command=quit --menu='Example!echo sample >text.txt'
The problem is that yad doesn't accept redirection, so it literally prints the string sample >text.txt
instead of redirecting.
Likewise, the pipe symbol (|
) is a separator in yad; but if you change that, yad takes it as a literal character. For example:
yad --notification --command=quit --separator='#' --menu='Example!echo sample | tee text.txt'
This literally prints the string sample | tee text.txt
instead of piping.
There's also no point in writing a function for yad to call, because yad runs in its own space and doesn't recognise the function.
Hence my question
Thus, I want a command like echo
, cat
or printf
that takes an output file as an argument rather than a redirect. I have searched for such a command but cannot find it.
I can, of course, write my own and put it in the default path:
FILENAME="${1}"
shift
printf '%s\n' "${*}" >"${FILENAME}"
and then
yad --notification --command=quit --menu='Example!myscript text.txt sample'
But, I'll be surprised indeed if Linux doesn't already have something like this!
Thank you
yad --notification --command=quit --menu='Example!echo sample' > text
?yad
dd of=myName status=none
copies stdin to the named file without invoking any additional syntax or processes.awk 'BEGIN{print "sample text" >"filename"}
or to make it work in a single-quoted argument to yadawk -v d="sample text" -v f="filename" "BEGIN{print d >f}"