简体   繁体   中英

Shell script : how to output to command line?

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!

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?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM