English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Comando echo di Shell

The echo command in Shell is similar to the echo command in PHP, both of which are used for string output. Command format:

echo string

You can use echo to implement more complex output format control.

1. Displaying ordinary strings:

echo "It is a test"

The double quotes can be omitted here. The following command has the same effect as the above example:

echo It is a test

2. Displaying escape characters

echo \

The result will be:

"It is a test"

Anche le virgolette doppie possono essere omesse

3. Visualizzazione delle variabili

Il comando read legge una riga dall'input standard e assegna il valore di ogni campo al variabile shell

#!/bin/sh
read name 
echo "$name It is a test"

Il codice sopra deve essere salvato come test.sh, la variabile name riceve il valore dell'input standard, il risultato sarà:

[root@www ~]# sh test.sh
OK  # Input standard
OK It is a test  # Output

4. Visualizzazione con a capo

echo -e "OK! \n" # -e abilita l'escapamento
echo "It is a test"

Risultato di output:

OK!
It is a test

5. Visualizzazione senza a capo

#!/bin/sh
echo -e "OK! \c" # -e abilita l'escapamento \c non a capo
echo "It is a test"

Risultato di output:

OK! It is a test

6. Visualizzazione del risultato direzionata al file

echo "It is a test" > myfile

7. Output della stringa originale, senza scappamento o variabile (usare apici singoli)

echo '$name\"'

Risultato di output:

$name\"

8. Visualizzazione del risultato dell'esecuzione del comando

echo `date`

Attenzione: Qui viene utilizzato l'apice `, invece dell'apice singolo '。

I risultati verranno visualizzati con la data corrente

Gio 24 Lug 10:08:46 CST 2018