Bash: Variables

Değişkenler, herhangi bir dilde çalışırken ilk öğretilen konulardan biridir. Bash’e giriş yaparken, değişkenlerle başlayacağım. Nasıl değişken tanımlanır? Sık kullanılan built-in değişkenler hangileridir?

Assign Variables

Bash’de çalışırken aşağıdaki gibi değişkenler tanımlanabilir.

str="Hello, there!"
echo $str
> Hello, there!

Değişkenleri bazı (attribute) özelliklerle tanımlamak da mümkün.

declare -i d=123                                    # Integer
declare -r e="Haha, I'm read only."                 # Read-Only
declare -l b="This text is gonna be lowercase."     # Lower-Case
declare -u c ="This text is gonna be UPPERCASE"     # Upper-Case

Built-In Variables

Aşağıda sık kullanılan bazı built-in variablelar listelenmiştir. Fazlası için The Linux Documentation Project

echo $HOSTNAME
echo $MACHTYPE
echo $HOME
echo $PWD
echo $SECONDS           # Returns the number of seconds the Bash session has run
                        # If used in a script, it'll start counting from when the script started.
echo $0                 # Returns the name of the script.
echo $BASH              # Returns the path to the BASH binary. /bin/bash
echo $BASHPID           # Process ID of the current instance of Bash.
echo $BASH_VERSION
echo $PATH              # Path to binaries. Usually /usr/bin/, /usr/X11R6/bin/, /usr/local/bin, etc.

Next Episode

published on 16.11.2019

val=a + a - a * a / a ** a % a > 27 let "a = 3 ** 3" echo $a > 27 Double Parentheses let, ile çalışabileceğimiz gibi çift parantez kullanarak da bash’e aritmatik operasyon yapılmasını gerektiğini anlatabiliriz.

TAG CLOUD