Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any alternatives to the "echo" command?

Tags:

bash

shell

unix

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

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

like image 632
Fence_rider Avatar asked Feb 17 '14 00:02

Fence_rider


People also ask

Which command is used instead of echo command?

Which command is used as an alternative to echo command? Explanation: printf command is available on most UNIX systems and it behaves much like a substitution for echo command. It supports many of the formats which are used by C's printf function.

Is printf better than echo?

Printf provides for the creation of a formatting string and offers a non-zero quit status when it fails. Whereas echo normally leaves with a 0 status and typically outputs inputs headed by the end of line character upon this standard result. The “printf” gives you more options for the output format than the “echo”.

Why do we need echo command?

echo command in linux is used to display line of text/string that are passed as an argument . This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file.

What is the difference between cat and echo command?

cat is for listing contents of any file. echo is for listing value of some variable. Besides, echo without any value is used to insert a new line in many shell scripts. For more subtle and complete difference you can always google.


1 Answers

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

#!/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"
like image 50
rainkinz Avatar answered Oct 20 '22 08:10

rainkinz