What is the meaning of the symbol ":" and "?

Asked

Viewed 431 times

1

The example I don’t quite understand is:

cut -d : -f /etc/passwd | tr : \\t

What do the two dots mean : and the two bars \\?

  • -d : = fields separated by : (-f missing list of components to select) tr : '\t'replaces ":" by tabs. cut -d : -f 1,5 /etc/passwd | tr : '\t' para username e nome


1 answer

3

As well as several programming languages, when writing a String, and there are strings that return a value like:

"\a" --> Sinal sonoro
"\n" --> Quebra de linha
"\t" --> Tabulação horizontal

And in Shellscript the backslash or Arrab works the same, but in this case, every character that is after the Arrab is passed to String.

sh ~: touch my keys # cria os arquivos my e keys
sh ~: touch my\ keys # cria o arquivo my keys

And when you put them in sequence \\, is written to arrab.

sh ~: echo escreve-ndo \\ arrab
#escrevendo \ arrab

Already the :, has a difference where it is employed in the case of cut -d : is creating a delimiter for the information that will be launched.

echo "Saida: Meu texto!!!!" > saida
cut -d : -f 1 saida
#Saida

That is, it will write the content even before the :.

In tr the : represents a character to be replaced.

echo "dados:lista" | tr : \- # dados-lista

But the : in some cases, it can be used to assign null value to files or to a disk.

echo "dados para o arquivo" > arquivo
:>arquivo
cat arquivo

File content will be empty.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.