User Tools

Site Tools


misc:code_snippets:shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
misc:code_snippets:shell [2016/09/27 15:04] – created saschamisc:code_snippets:shell [2025/11/22 09:10] (current) – Einzeiler für Basispfad des ausgeführten Skripts sascha
Line 36: Line 36:
  
   cd -   cd -
 +
 +==== Basispfad des ausgeführten Skripts ermitteln ====
 +
 +  DIR=$( cd -- "$( dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || ${BASH_SOURCE[0]})" )" &> /dev/null && pwd )
 +
 +Folgt auch Symlinks und funktioniert, wenn es mit ''source'' ausgeführt wird, ''#!/bin/sh'' hat bei mir ebenfalls geklappt.
  
 ==== Formatierung ''date'' ==== ==== Formatierung ''date'' ====
Line 91: Line 97:
   round 42/3.14159   round 42/3.14159
   round 17/13 7   round 17/13 7
 +
 +==== Überprüfen, ob Kernel-Module geladen sind ====
 +
 +<code bash check_module.sh>
 +#!/bin/sh
 +
 +# check if a kernel module is loaded
 +
 +[ "$1" == "" ] && echo "Usage: $0 MODULE [q]" && exit 0
 +
 +#if lsmod | grep -Eq "$1" &> /dev/null ; then
 +if grep -Eq "$1" /proc/modules &> /dev/null ; then
 +    [ "$2" == "q" ] || echo "$1 is loaded!"
 +    exit 0
 +else
 +    [ "$2" == "q" ] || echo "$1 is not loaded!"
 +    exit 1
 +fi
 +</code>
  
  
 {{tag>linux shell bash scripting programming}} {{tag>linux shell bash scripting programming}}
misc/code_snippets/shell.1474988646.txt.gz · Last modified: (external edit)