echo (comandă)

(Redirecționat de la Echo (computing))

În sistemele de operare UNIX, Windows și OS/2, comanda echo tipărește textul specificat pe linia de comandă. Comanda este folosită adeseori în scripturi shell. Sub Linux, comanda este implementată în GNU coreutils.

Sintaxă modificare

echo [opțiuni] string

Opțiunile cele mai des folosite sunt:

-n - nu tipări new line (\n)
-e - interpretează secvențele de caractere \

Secvențele de caractere \ interpretate sunt:

  • \\ - backslash
  • \a - alertă (BEL)
  • \b - backspace
  • \c - comentariu, după acest caracter nu se mai tipărește
  • \f - form feed
  • \n - new line
  • \r - carriage return
  • \t - tab orizontal
  • \v - tab vertical

Datorită incompatibilităților dintre BSD și System V, opțiunile -n și -e nu sunt considerate opțiuni standard.

Exemple modificare

# echo This is a test.
This is a test.
# echo "This is a test." > ./test.txt
# cat ./test.txt
This is a test.

Exemplu de script care folosește secvențe escape ASCII:

FGRED=`echo "\033[31m"`
FGCYAN=`echo "\033[36m"`
BGRED=`echo "\033[41m"`
FGBLUE=`echo "\033[35m"`
BGGREEN=`echo "\033[42m"`
NORMAL=`echo "\033[m"`

echo "${FGBLUE} Text in blue ${NORMAL}"
echo "Text normal"
echo "${BGRED} Background in red"
echo "${BGGREEN} Background in Green and back to Normal ${NORMAL}"

Exemplu de implementare în limbaj C modificare

#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;
}

Legături externe modificare


 v  d  m  Programe în linia de comandă pentru Unix (mai multe)
Management de fișiere: cat | cd | chmod | chown | chgrp | cksum | cmp | cp | du | df | file | fsck | ln | ls | lsof | mkdir | mount | mv | pwd | rm | rmdir | split | touch
Management de procese: at | chroot | cron | exit | kill | killall | nice | pgrep | pidof | pkill | ps | pstree | sleep | time | top | wait
Management utilizator/mediu: env | finger | id | mesg | passwd | su | sudo | uname | uptime | w | wall | who | whoami | write
Procesare text: awk | comm | cut | ed | ex | fmt | head | iconv | join | less | more | paste | sed | sort | tac | tail | tr | uniq | wc | xargs
Programare Shell: basename | echo | expr | false | printf | test | true | unset Imprimare:
lp
Communicații:
inetd | netstat | ping | rlogin | traceroute
Căutare:
find | grep | strings
Diverse:
banner | bc | cal | dd | man | size | yes