Čo znamená percento prihlášok Linux Shell Strings Do?

Obsah:

Čo znamená percento prihlášok Linux Shell Strings Do?
Čo znamená percento prihlášok Linux Shell Strings Do?
Anonim
Keď ste v procese učenia, ako plne používať Linux shell, môžete zistiť, ako veľmi môžete manipulovať s reťazcami, aby ste dosiahli najlepšie výsledky. S ohľadom na to má dnešný príspevok SuperUser Q & A odpoveď na otázku zvedavého čitateľa.
Keď ste v procese učenia, ako plne používať Linux shell, môžete zistiť, ako veľmi môžete manipulovať s reťazcami, aby ste dosiahli najlepšie výsledky. S ohľadom na to má dnešný príspevok SuperUser Q & A odpoveď na otázku zvedavého čitateľa.

Dnešná relácia otázok a odpovedí sa k nám pridelí zdvorilosťou SuperUser - podskupiny Stack Exchange, skupín webových stránok týkajúcich sa otázok a odpovedí.

Otázka

Čítačka SuperUser Nissim Kaufmann chce vedieť, aké percento znamení v reťazcoch Linux shell:

When using the Linux shell, what does the percent sign (%) do? For example:

Image
Image

Čo robí percento znamenia v reťazcoch Linux shell?

Odpoveď

Sponzor SuperUser Marek Rost má pre nás odpoveď:

When the percent sign (%) is used in the pattern ${variable%substring}, it will return content of the variable with the shortest occurrence of substring deleted from the back of the variable.

This function supports wildcard patterns, that is why it accepts an asterisk (star) as a substitute for zero or more characters. It should be mentioned that this is Bash specific. Other Linux shells do not necessarily contain this function.

If you want to learn more about string manipulation in Bash, then I highly suggest reading the following page, Advanced Bash-Scripting Guide: Chapter 10. Manipulating Variables. Among many other handy functions, it explains what a double percent sign (%%) does, for example.

I forgot to mention that when it is used in the pattern $((variable%number)) or $((variable1%$variable2)), the percent sign (%) character will function as a modulo operator.

When the percent sign (%) is used in different contexts, it should be recognized as a regular character only.

Máte niečo doplniť vysvetlenie? Znížte komentáre. Chcete si prečítať viac odpovedí od iných používateľov technológie Stack Exchange? Pozrite sa na celý diskusný príspevok tu.

Image Credit: Linux Screenshoty (Flickr)

Odporúča: