I would like to send via a shell script a command to my XTerm.
For instance, I would like a shell script of mine to perform the command "clear-saved-lines()" to my Xterm.
Indeed, I don't want to use /usr/bin/clear but a command that erases everything in my xterm.
You can have XTerm translate keystrokes into "actions". (See the man page, search for "Actions"). As an example, you'd add this to your X resource file:
That means that F11 will execute your function in the Xterm. How do you get such a key to Xterm? First, get the WindowID of your xterm. Then, use xvkbd:
Getting the WindowID is, well, it depends on your needs and it's not normally done from the command line. But several solutions exist. You can find these solutions described here and here.
Now it's possible to have a process send keystrokes into another X window.