views:

58

answers:

3

I'm making a shell script and I want to know if it's possible to write directly to the command line when the script is executed ?

Example :

user@localhost:/home/user$./script.sh
... output
... another output
... another output
... last output
user@localhost:/home/user$I want to write here on the command line

I don't want to "echo" some text, I want to write directly at the prompt.

Thanks!

+2  A: 

No, you can't do that. If you want user to invoke your provided command after your script is finished - why not just prompt user for confirmation?

Eimantas
Great idea ... I will proceed this way as I can't write at the prompt. Thank you
elblanco
A: 

If you just want the text to show up there, but not be able to do anything with it, you can do this.

File test.sh:

echo "Output"
./test2.sh &

File test2.sh:

echo "Output2"

Notice how the first script calls the second script with the & at the end.

In this case, "Output2" will be written to the prompt, but it can't be deleted and will have no effect on the next command at all. But if this is something you're doing to grab the user's attention, it would work.

Serplat
Thank you ... but I want the user to just hit enter to execute the command when he will be ready
elblanco
A: 

In ksh:

print -s $(script)

will print to the command history. Wrap this in a function and you'll have something close to what you are asking for.

Darron
Thank you but I can't use ksh.
elblanco