25 Aralık 2021 Cumartesi

readlink komutu

Giriş
Symbolic linkleri çözümlemek için kullanılır

-f seçeneği
Açıklaması şöyle
-f, --canonicalize canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist
Örnek
awk komutu bir symbolic link olsun. Gerçekte nereye işaret ettiğini görmek için şöyle yaparız
$ readlink -f -- "$(which awk)"
/usr/bin/gawk

16 Aralık 2021 Perşembe

bash kodlama Positional Parameter için gömülü değişkenler

Giriş

Positional Parameter Salt Okunurdur
Açıklaması şöyle.
You can't assign to the positional parameters individually
$0 değişkeni - positional parameter
Örnek
Şöyle yaparız. Bize shell ismini gösterir. Mesela çıktı olarak "bash" yazar.
echo $0
Örnek - Yapmayın
Şöyle yaparız.  Mevcut shell için yeni bir shell daha başlatır.
$0
Açıklaması şöyle
As $0 contains the shell command that is running your shell script or interactive session; when you type $0 in a terminal, you are invoking the command name within the $0 argument variable.

When $0 contains bash; Typing $0 in the terminal, just runs bash. It then runs another bash within the scope of the first one, as a sub-shell.

As it runs another shell, it look like it did nothing, but started another shell session with same environment variables and settings. The shell prompt and current directory are exactly the same, so it look like nothing happened.

If you then try to close the terminal window, while a sub-shell has been invoked, it will tell you there are still background processes running.

What happens when you close the terminal window, is: It signals the first higher level shell Process ID to terminate, but this shell's PID know it has some child PID still attached, and just tells you about it.
$1 değişkeni - positional parameter
İki tane parametre alan basit bir metod için şöyle yaparız.
qh() {
  "$1" --help | grep -- "$2"
}
$9'dan sonra gelen değişkenler
$9'dan sonra gelen değişkenlere - örneğin 14. değişken olsun - $14 olarak erişemiyoruz. erişmek için ${X} şeklinde süslü parantez içine almak lazım. Açıklaması şöyle
The list of positional parameters can be as long as required and as current resource limits allows. This means that there may be well over 9 elements in the list. As you have already noticed, elements 10 and later may be accessed by adding braces around the number, as in ${12}.

Örnek
Elimizde şöyle bir script olsun. Bunu file isimli bir dosyaya kaydedelim
#! /bin/bash
echo $14
Daha sonra çalıştıralım. İstediğimiz 14 çıktısını alamayız
./file 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Doğru çıktıyı almak için şöyle yaparız
echo ${14}

9 Aralık 2021 Perşembe

SIGSEGV

Giriş
Açıklaması şöyle. 
The signal SIGSEGV is standardized but different OS might implement it differently. "Segmentation fault" is mainly a term used in *nix systems, Windows calls it "access violation".

6 Aralık 2021 Pazartesi

3 Aralık 2021 Cuma

/usr/lib Dizini

Giriş
/lib, /usr/lib, /var/lib dizinleri arasında fark var. Açıklaması şöyle. Yani /lib ve /usr/lib dizinleri salt okunur olarak kullanılmalı. /lib dizininde sisteme ait şeyler olur. /usr/lib dizininde kullanıcıya ait uygulamalar olur
Someone else can probably explain this with much more detail and historical reference but the short answer:
/lib
is a place for the essential standard libraries. Think of libraries required for your system to run. If something in /bin or /sbin needs a library that library is likely in /lib.

/usr/lib
the /usr directory in general is as it sounds, a user based directory. Here you will find things used by the users on the system. So if you install an application that needs libraries they might go to /usr/lib. If a binary in /usr/bin or /usr/sbin needs a library it will likely be in /usr/lib.

/var/lib
the /var directory is the writable counterpart to the /usr directory which is often required to be read-only. So /var/lib would have a similar purpose as /usr/lib but with the ability to write to them.

21 Kasım 2021 Pazar

bash array - Array Expansion

Giriş
Array expansion veya tüm Diziyi Dolaşmak için "${myarr[@]}" veya "${myarr[*]}" kullanılır

Aralarındaki fark şöyle. Muhtemelen "${myarr[*]}" daha iyi.
If subscript is @ or *, the word expands to all members of name. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the first character of the IFS special variable, and ${name[@]} expands each element of name to a separate word. When there are no array members, ${name[@]} expands to nothing. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word.
1. [@] Kullanımı
Örnek
Şöyle yaparız. Bir dosyadaki tüm satırları okuyup hepsini find komutuna geçeriz.
readarray -t a < pathlist.txt
find "${a[@]}" -type f ....
Örnek
Şöyle yaparız
declare data
data="pig,cow,horse,rattlesnake,"
declare -a my_array
IFS=',' read -r -a my_array <<< "$data"
for item in "${my_array[@]}"; do echo "$item"; done
Örnek
Şöyle yaparız
dirs=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)

for dir in "${dirs[@]}"
do
 mkdir -p $dir
done
Örnek
Bir diğer seçenek olarak ${#array[@]} ile uzunluğunu alıp array[i] ile indeksine erişiriz. Şöyle yaparız.
for ((i=0 ; i < ${#array[@]} ; i++ )) ; do
    echo "${array[i]}"
done
2. [*] Kullanımı

Örnek

Şöyle yaparız. Kullanıcıdan sayı okunur. Daha sonra array değişkeni her bir elemanın etrafında boşluk karakteri olacak şekilde expand edilir. Daha sonra bu string içinde düzenli ifade kullanılarak arama yapılır
#!/bin/bash

array=( "one" "two" "three" "four" "five" )

function get_input() {
  read -p "${1}: " number
  if [[ " ${array[*]} " == *" ${number} "* ]]
  then
    echo 'true';
  else
    get_input 'Try again'   # a recursive call of the function
  fi
}

get_input 'Enter a number'  # the initial call of the function

17 Kasım 2021 Çarşamba

kind - Yerel Kubernetes Cluster

Giriş
Açıklaması şöyle
Kind runs a local kubernetes cluster in Docker container and is an effective use to manage local kubernetes cluster deployment. The other alternative for local k8s cluster management is minikube...
create seçeneği
Örnek
Şöyle yaparız
kind create cluster --name local-dev
Örnek -- config
Elimizde şöyle bir yaml olsun
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 31234
    hostPort: 8080
    protocol: TCP
Şöyle yaparız
kind create cluster --name local-dev --config k8s-cluster-config.yaml
delete seçeneği
Örnek
Şöyle yaparız
kind delete cluster --name local-dev
get clusters seçeneği
Örnek
Şöyle yaparız
$kind get clusters
local-dev
get services seçeneği
Örnek
Şöyle yaparız
$kubectl get services

NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   5m53s