Use of% in variables

3

I can not understand what this symbol is for in a variable, I see its use in some points in SQL code, Shell Script, C. What is the use?

For example a use of this symbol in Shel Script:

DATA=$(date +%H)

The variable DATA receives the (current date +% H)

I do not understand what '%' is

    
asked by anonymous 14.05.2017 / 18:54

1 answer

3

In Shell Script this is a formatting indicator, so it will take the result of date and apply the format that the programmer set up next, in case the %H indicates that you want to take only the time. The % symbol, in this context, is only to indicate the pattern you want, not to be ambiguous with normal letters.

Of course in other languages there are similar things. It is an escape character indicated that the following is a formatting code and not a normal character to display.

This is not used in variables but in string literals.

    
14.05.2017 / 18:57