Bash

From My Mnemonic Rhyme
Revision as of 11:57, 5 May 2025 by Weiss (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Bash Files

FILES
       /bin/bash
              The bash executable
       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bashrc
              The systemwide per-interactive-shell startup file
       /etc/bash.bash.logout
              The systemwide login shell cleanup file, executed when  a  login
              shell exits
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file
       ~/.bash_logout
              The  individual  login shell cleanup file, executed when a login
              shell exits
       ~/.inputrc
              Individual readline initialization file

Links

for loop over list of strings

strings=(
    string1
    string2
    "string with spaces"
    stringN
)
for i in "${strings[@]}"; do
    echo "$i"
done


Bedingungen

Bedingungen für test Ausdruck	Beispiel	Erklärung
-d verzeichnis	[ -d /tmp ]	Ist wahr, wenn die Datei existiert und ein Verzeichnis ist.
-f datei	[ -f txt.txt ]	Ist wahr, wenn die Datei existiert und eine normale Datei ist.
-w datei	[ -w text.txt ]	Ist wahr, wenn die Datei existiert und den Schreibzugriff erlaubt.
-x datei	[ -x script.sh ]	Ist wahr, wenn die Datei existiert und die Ausführung erlaubt.
-n string	[ -n "$name" ]	Ist wahr, wenn die übergebene Zeichenkette nicht leer ist.
str1 = str2	[ "$1" = "Hallo" ]	Ist wahr, wenn beide Zeichenketten identisch sind.
z1 -eq z2	[ 1 -eq $summe ]	Ist wahr, wenn beide Zahlen gleich groß sind (in Bedingungen wird zwischen Zahlen und Zeichenketten unterschieden).
z1 -lt z2	[ 17 -lt $zahl ]	Ist wahr, wenn die erste Zahl kleiner als die zweite Zahl ist (lt = lower then).
z1 -gt z2	[ 28 -gt $tag ]	Ist wahr, wenn die erste Zahl größer als die zweite Zahl ist.
z1 -ne z2	[ $zahl -ne 7 ]	Ist wahr, wenn beide Zahlen ungleich sind.
! ausdruck	[ ! 1 -eq $zahl ]	Ist wahr, wenn der Ausdruck falsch ist (also eine Negierung).

Strings

= 	equal
!= 	not equal
< 	less then
> 	greater then
-n s1 	string s1 is not empty
-z s1 	string s1 is empty

Scriptfetzen

#Auth Log durchsuchen:
cat /var/log/auth.log | grep "Invalid user" | cut -d ':' -f 1,2,4 | sort | uniq

genpasswd() {
	local l=$1
       	[ "$l" == "" ] && l=16
      	tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}

Easteregg

  47 # -----------------
  48 # Easter Egg alert!
  49 # -----------------
  50 #  Chet Ramey seems to have snuck a bunch of undocumented C-style
  51 #+ constructs into Bash (actually adapted from ksh, pretty much).
  52 #  In the Bash docs, Ramey calls (( ... )) shell arithmetic,
  53 #+ but it goes far beyond that.
  54 #  Sorry, Chet, the secret is out.