echo (command)
From Wikipedia, the free encyclopedia
In computing, echo is a command in DOS, OS/2, Microsoft Windows, Singularity, Unix and Unix-like operating systems that places a string on the computer terminal. It is typically used in shell scripts and batch files to output status text to the screen or a file.
Contents |
[edit] Usage example
$ echo This is a test. This is a test. $ echo "This is a test." > ./test.txt $ cat ./test.txt This is a test.
Some variants of Unix support options such as -n and -e. These are not standard[1] due to historical incompatibilities between BSD and System V; the printf command can be used in situations where this is a problem.
Using ANSI escape code SGR sequences, compatible terminals can print out colored text:
FGRED=`echo "\033[31m"` FGCYAN=`echo "\033[36m"` BGRED=`echo "\033[41m"` FGBLUE=`echo "\033[35m"` BGGREEN=`echo "\033[42m"` NORMAL=`echo "\033[m"` and after : echo "${FGBLUE} Text in blue ${NORMAL}" echo "Text normal" echo "${BGRED} Background in red" echo "${BGGREEN} Background in Green and back to Normal ${NORMAL}"
[edit] Implementation example
The echo command can be implemented in the C programming language with only a few lines of code:
#include <stdlib.h> #include <stdio.h> /* echo command-line arguments; 1st version */ int main(int argc, char *argv[]) { int i; for (i = 1; i < argc-1; i++) { (void) printf("%s%s", argv[i], " "); } (void) printf("%s%s", argv[argc-1], "\n"); return EXIT_SUCCESS; }
Perl can also emulate echo quite simply:
#!/usr/bin/env perl print join " ", @ARGV
[edit] References
[edit] External links
- : write arguments to standard output – Commands & Utilities Reference, The Single UNIX® Specification, Issue 7 from The Open Group
- Microsoft TechNet Echo article
[edit] See also
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| This Unix-related article is a stub. You can help Wikipedia by expanding it. |
| This Microsoft Windows article is a stub. You can help Wikipedia by expanding it. |