Solved How to print a variable on STDOUT while still have the hand

Hello,

Is it possible to display a variable on STDOUT and keep the hand in order to use/edit it ?
I've tried to remove the carriage return or newline with tr , or changing IFS but that didn't work.
So after few hours on this I just wonder if it is possible, if yes what command/tool can do that ?

It is probably not well explained so to illustrate what I would like to do in the following example just pretend the cursor is represented by "__"

normal:
Code:
$ echo foo 
$ foo 
$ __
expected:
Code:
$ echo foo 
$ foo __

Thank you.
 
Humm I am not sure I've already tried this.
echo -n just remove the newline but you won't have the hand after that.

Still using "__" to illustrate the cursor :
Code:
~ : echo -n "foo"                                        
foo~ : __
 
I don't understand what you mean then, sorry.
No problem, I had some hard time trying to figure out how I can explain it to people, I suppose I didn't express myself well enough.
That's why I choose to put an example to show what I want, I thought it could be better to understand than my poor explanation, but apparently it's not ^^

he wants the var back in his input
Well that's probably the correct way to explain it. thanks.
 
Thanks but would it be possible to achieve it in shell sh instead or is it a too complicated task to be done in shell?
I don't ask necessarily people to do it for me, just put me in the right direction is also good enough.
 
i don't think its possible to do it without an external command (ie with a shell built in function)
so you need an external command
and then in the shell or shell script you use it
save the python script in your path, add a shebang line, make it executable and use it like
stuffinput $VAR
 
I'm struggling to understand exactly what you mean by "keep in hand". If you know the value of the shell variable you display on STDOUT, then you can re-use it at will, or you can infer a default. Here is portable Bourne shell code to achieve a similar (and very common) outcome to what (I think) you want:
Code:
# Implement BSD "echo -n"
case `echo -n` in
    -*) Echon() { echo ${1:+"$@"}"\c"; };;
    *)  Echon() { echo -n ${1:+"$@"}; };;
esac
DefaultAnswer="Y"
Echon "Do you wish to proceed [$DefaultAnswer/n]? "
read Answer
[ -z "$Answer" ] && Answer="$DefaultAnswer"
Answer=$(echo $Answer | tr '[A-Z]' '[a-z]')
echo "The answer (in lower case) is $Answer"
 
Do you want something like this?
Code:
#!/bin/sh
for pc in $(seq 1 100); do
    printf "[%6.2f%%]\r" $((pc))
    sleep 1
done
 
i don't think its possible to do it without an external command (ie with a shell built in function)
so you need an external command
It looks a lot like it.
Found a solution implying external tools like you said (xdotool+xclip) .
Thank you for the term "tiocsti", starting with it I found my way around it, but in vain because in the end it doesn't really help me the way I thought it would, obviously my approach wasn't good from the beginning but at least I learned something.


Jose , yuripv79 , Charlie_ , gpw928
Sorry if my question was not clear, next time I will try to rephrase it.

if you still don't get it, it appears that what I wanted to do can be done via tmux.
launch tmux
$ tmux

then inside tmux enter:
$ stty -echo; tmux send-keys the_text ; stty echo
the result is : the prompt, the string the_text, and the waiting cursor

Anyway I switched to something else for now, the case is closed for me.

Thank you guys for your help.
 
Back
Top