1

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!

3
  • As such, no, not as far as I know. Commented Aug 23, 2010 at 18:43
  • What do you need this for? I know a way to get it to print the text, but you can't get rid of the text via backspace, and the text won't have any effect on your next command. But I doubt that's what you're looking for. Commented Aug 23, 2010 at 18:56
  • @Serplat : The text is a command that the user will execute when he will be ready. Commented Aug 23, 2010 at 19:15

4 Answers 4

5

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Great idea ... I will proceed this way as I can't write at the prompt. Thank you
0

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.

1 Comment

Thank you ... but I want the user to just hit enter to execute the command when he will be ready
0

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.

2 Comments

Thank you but I can't use ksh.
@codea I understand, of course, that you may not be able to use ksh, but can you definitely not use it? If there's a particular limitation then we might be able to work around that.
0

If you are using X environment install xclip and xdotool, then:

#!/bin/bash
your scripts....
echo -n your command to write 2>&1|xclip
xdotool click 2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.