Ką užima "Linux" "Shell" eilučių procentinė dalis?

Turinys:

Ką užima "Linux" "Shell" eilučių procentinė dalis?
Ką užima "Linux" "Shell" eilučių procentinė dalis?

Video: Ką užima "Linux" "Shell" eilučių procentinė dalis?

Video: Ką užima
Video: Michael Duyzend - Developing a culture of constructive criticism - YouTube 2024, Balandis
Anonim
Kai esate mokymosi procese, kaip visapusiškai naudotis "Linux" apvalkalu, galite sužinoti, kiek galite manipuliuoti stringsmis, kad gautumėte geriausius rezultatus. Atsižvelgdami į tai, šiandieninis SuperUser Q & A pranešimas turi atsakymą į įdomų skaitytojo klausimą.
Kai esate mokymosi procese, kaip visapusiškai naudotis "Linux" apvalkalu, galite sužinoti, kiek galite manipuliuoti stringsmis, kad gautumėte geriausius rezultatus. Atsižvelgdami į tai, šiandieninis SuperUser Q & A pranešimas turi atsakymą į įdomų skaitytojo klausimą.

Šiandieninė klausimų ir atsakymų sesija pateikiama su "SuperUser" - "Stack Exchange", bendruomenės valdoma Q & A grupių asociacija.

Klausimas

"SuperUser" skaitytojas Nissim Kaufmann nori sužinoti, koks yra "Linux" apvalkalo stygų procentinis žymuo:

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

Image
Image

Ką rodo "Linux" apvalkalo stygų procentas?

Atsakymas

"SuperUser" autorius Marekas Rostas turi mums atsakymą:

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.

Ar turite ką nors įtraukti į paaiškinimą? Garsas išjungtas komentaruose. Norite skaityti daugiau atsakymų iš kitų "Tech-savvy Stack Exchange" vartotojų? Patikrinkite visą diskusijų temą čia.

Vaizdo kreditas: "Linux" ekrano nuotraukos ("Flickr")

Rekomenduojamas: