17 Ağustos 2020 Pazartesi

bash brace expansion - Girdiye Süslü Parantez İçindeki Listeyi Ekleyerek Çoklar

Giriş
Açıklaması şöyle. Yani #!/bin/sh şeklinde shebang kullanan kabuklarda çalışmaz.
Brace expansion is not standardized by POSIX. Some, but not all, of the widely used Bourne-style shells support it.
Örnek - Tek Girdi
Brace yani süslü parantez içinde iki tane girdi kullanmak gerekir. Bu girdiler değişken veya sabit olabilir. Elimizde şöyle bir kod olsun. Burada a ve b için açılım yapılıyor
$ echo --hidden-import={a,b}
--hidden-import=a --hidden-import=b
Ancak burada tek girdi olduğu için brace expansion yapılmıyor
echo --hidden-import={$FILES}
--hidden-import={cpu_mon disk_mon mem_mon network_mon}
Açıklaması şöyle
If you have {$x,$y} the shell first processes it into two arguments $x and $y, and only then expands the variables within each argument separately. And if you have only one item, brace expansion doesn't happen at all; {xy} always remains just {xy}.

Örnek
Şöyle yaparız
for i in {2..5}; do cp -r /home/test/DS1 "DS$i"; done
Örnek
Şöyle yaparız.
echo test{1,2}
test1  test2
Örnek
Şöyle yaparız
printf '%s\n' {0..4..2}" "{0..2..2}
Çıktı olarak şunu alırız
0 0
0 2
2 0
2 2
4 0
4 2


Hiç yorum yok:

Yorum Gönder