FLOSSK site

echo

From FLOSSK Wiki

Jump to: navigation, search

In computing, echo is a command (computing)|command in DOS, OS/2, Microsoft Windows, Singularity (operating system)|Singularity Unix and Unix-like operating systems that places a String (computer science)|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.

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 standardIEEE Std 1003.1, 2004, documentation for echo due to historical incompatibilities between BSD and System V; the printf command can be used in situations where this is a problem.

Implementation example

The echo command can be implemented in the C programming language with only a few lines of code:

#include <stdio.h>
/* echo command-line arguments; 1st version */
int main(int argc, char *argv[])
{
  int i;
  for (i = 1; i < argc; i++)
    printf("%s%s", argv[i], (i < argc-1) ? " " : "");
  printf("\n");
  return 0;
}