28 Nisan 2020 Salı

shopt komutu

-s seçeneği 
1. direxpand
Örnek
Şöyle yaparız.
if shopt -s direxpand 2>/dev/null; then
   # the direxpand option exists
else
   # the direxpand option does not exist
fi
2. extglob
Adı extglob ama aslında bash içinde regular expression işlevinin etkinleştirilmesi demek
bash kabuğunda KSH-style extended glob etkindir. Bu yüzden sanırım parantez içinde glob için karakter verebilmeyi sağlıyor. Bu özelliği bash içinde de etkinleştirmek için kullanılır. Açıklaması şöyle
Extended globs like +(...) aren't enabled in Bash by default, you'll need to explicitly use shopt -s extglob in the script to enable them.
Örnek - +(...)
bash satırından çalıştırınca sonuç şöyle. Arka arkaya gelen tüm space karakterlerini tek space karakteri ile değiştirir
$ s='1 2,   3   4,'
$ s0="$(echo ${s//,/ }|tr -s ' ')"
$ echo "s0: $s0"
s0: 1 2 3 4
$ d="'${s0//+([[:space:]])/"' '"}'"
$ echo "d: $d"
d: '1' '2' '3' '4'
Örnek - *(...)
Açıklaması şöyle
The expression *([0-9]).conf is a KSH-style extended glob. The feature is enabled by default for interactive bash shells, but to use it in a bash script it must be enabled explicitly using shopt -s extglob
Yani bash kabuğundan şöyle yapabiliriz
ls /etc/pve/lxc/*([0-9]).conf
Ama bash içinden bu çalışmaz.
#!/bin/bash
ls /etc/pve/lxc/*([0-9]).conf

Çıktı olarak
Result: ERROR
syntax error near unexpected token `('
Örnek - ? karakteri
Elimizde şöyle bir kod olsun. Burada te?xt örüntüsünün text uzantılı dosyaları bulmasını bekleriz.
$ touch file.txt file.text
$ ls file.*
file.text  file.txt
$ ls file.te?xt
ls: cannot access 'file.te?xt': No such file or directory
Açıklaması şöyle.
The ? matches a single character (like . in a regular expression). You have no file matching the pattern file.te?xt so the pattern remains unexpanded.

You may have expected it to work as in a regular expression, where it means "zero or one of the previous expression". Unfortunately, there is no such wildcard in bash.
Şöyle yaparız
$ shopt -s extglob
$ ls file.t?(e)xt
file.text file.txt
3.  histverify
Açıklaması şöyle
If the histverify shell option is enabled, and Readline is being used, history substitutions are not immediately passed to the shell parser. Instead, the expanded line is reloaded into the Readline editing buffer for further modification.


Hiç yorum yok:

Yorum Gönder