bash “echo”命令有什么替代方法吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21818597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:35:29  来源:igfitidea点击:

Are there any alternatives to the "echo" command?

bashshellunix

提问by Fence_rider

is there a command other than "echo" that can be used to display text to the terminal, in bash?

除了“echo”之外,是否还有其他命令可用于在 bash 中向终端显示文本?

preferably one that can output to any point in the terminal.

最好是可以输出到终端中任何一点的。

回答by rainkinz

Maybe tput is what you're looking for. For example you could create a little menu like so:

也许 tput 就是你要找的。例如,您可以像这样创建一个小菜单:

#!/bin/bash

# clear the screen
tput clear

# Move cursor to screen location X,Y (top left is 0,0)
tput cup 3 15

# Set a foreground colour using ANSI escape. Not sure this works on OSX
tput setaf 3

# Set reverse video mode
tput rev
echo "S U S H I  M E N U  I T E M S"
tput sgr0

tput cup 5 17
echo "Please select an option"
tput sgr0

tput cup 7 15
echo "1. Sushi Sashimi Combo"

tput cup 8 15
echo "2. Omakase"

tput cup 9 15
echo "3. Chirashi"

tput cup 10 15
echo "4. Eel and Avacado Roll"


# Set bold mode 
tput bold
tput cup 12 15
read -p "Enter your choice [1-4] " choice

tput clear
tput sgr0
tput rc

echo "You chose $choice"