5 Haziran 2020 Cuma

bash Filename Expansion

Giriş
Açıklaması şöyle.
bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern. If no matching filenames are found, and the shell option nullglob is not enabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed.
glob altta ne yapar
Açıklaması şöyle
Using a feature of your shell called globbing or filename generation (pathname expansion in POSIX), not of the Linux system nor of any filesystem used on Linux.

te* is expanded by the shell to the list of files that match that pattern.

To do that, the shell requests the list of entries in the current directory from the system (typically using the readdir() function of the C library, which underneath will use a system-specific system call (getdents() on Linux)), and then match each name against the pattern.
Örnek
Şöyle yaparız. Burada elimize bir array geçer.
TXT=(*.txt)
Açıklaması şöyle.
will expand the *.txt pattern to the list filenames in the current directory that matches that pattern. The shell would do this at the time of the assignment.
Örnek
Şöyle yaparız.
echo ./*.txt
nullglob etkin değilse çıktı olarak şunu alırız
./*.txt
nullglob Etkinse
Açıklaması şöyle. Çıktı olarak sadece komut ve komut seçeneklerini alırız. Dizin ve dosya isimleri silinirler.
This makes ls * in an empty directory turn into plain ls, and rm -rf somepath/* where that subdirectory is empty turn into rm -rf.

Hiç yorum yok:

Yorum Gönder