Što se prijavljuje u Linux Shell Strings Do?

Sadržaj:

Što se prijavljuje u Linux Shell Strings Do?
Što se prijavljuje u Linux Shell Strings Do?

Video: Što se prijavljuje u Linux Shell Strings Do?

Video: Što se prijavljuje u Linux Shell Strings Do?
Video: The Anti-Smartphone Revolution - YouTube 2024, Travanj
Anonim
Kada ste u procesu učenja kako koristiti potpuno Linux ljusku, možda ćete biti znatiželjni koliko možete manipulirati žicama kako biste dobili najbolje rezultate. Imajući to na umu, današnji SuperUser Q & A post ima odgovor na pitanje čudnog čitatelja.
Kada ste u procesu učenja kako koristiti potpuno Linux ljusku, možda ćete biti znatiželjni koliko možete manipulirati žicama kako biste dobili najbolje rezultate. Imajući to na umu, današnji SuperUser Q & A post ima odgovor na pitanje čudnog čitatelja.

Današnja pitanja i odgovori nam se javljaju zahvaljujući SuperUseru - podjele Stack Exchange-a, zajednice-driven grupiranja Q & A web stranica.

Pitanje

SuperUser čitač Nissim Kaufmann želi znati što znak postotka u linux shell ligu:

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

Image
Image

Što čini postotak znakova u lancima Linux lancu?

Odgovor

Marek Rost ima odgovor za nas:

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.

Imate li nešto za objašnjenje? Zvuči u komentarima. Želite li pročitati više odgovora od drugih tehnoloških korisnika Stack Exchangea? Pogledajte ovdje cijelu raspravu.

Slika kredita: Linux snimke zaslona (Flickr)

Preporučeni: