Skip to content

other

A library of other related functions.

lb_gen_uuid

Return a generated uuid v4.

Parameters:
Name Type Description Default
None - - -
Examples:
#!/usr/bin/env bash

# shellcheck source=/dev/null
source ../init
source "${LIBBASH_DIR}/other"

function main() {
  printf 'lb_read_sleep\n'
  lb_read_sleep 1
  s=$(lb_gen_uuid)
  printf 'lb_uuid: %s\n' "${s}"
}

main "${@}"
Show source code in other
#!/usr/bin/env bash
: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"

#------------------------------ Global Variables ------------------------------

#------------------------------ Private Functions -----------------------------

#------------------------------ Public Functions ------------------------------

function lb_gen_uuid() {
  C="89ab"
  for ((N=0;N<16;++N)); do
    B="$((RANDOM%256))"
    case "$N" in
      6)        printf '4%x' "$((B%16))" ;;
      8)        printf '%c%x' "${C:$RANDOM%${#C}:1}" "$((B%16))" ;;
      3|5|7|9)  printf '%02x-' "$B";;
      *)        printf '%02x' "$B";;
    esac
  done
  printf '\n'
}

function lb_read_sleep() {
  lb_check_args_num "${@}" 1
  read -rt "${1}" <> <(:) || :
}

function lb_bkr() {
  ((${#@} == 0)) && lb_fail "expected at least 1 arg but got 0"
  (nohup "$@" &>/dev/null &)
}

lb_read_sleep time

Sleep for a certain period of item using the read command.

Parameters:
Name Type Description Default
time float The time to sleep in seconds required
Examples:
#!/usr/bin/env bash

# shellcheck source=/dev/null
source ../init
source "${LIBBASH_DIR}/other"

function main() {
  printf 'lb_read_sleep\n'
  lb_read_sleep 1
  s=$(lb_gen_uuid)
  printf 'lb_uuid: %s\n' "${s}"
}

main "${@}"
Show source code in other
#!/usr/bin/env bash
: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"

#------------------------------ Global Variables ------------------------------

#------------------------------ Private Functions -----------------------------

#------------------------------ Public Functions ------------------------------

function lb_gen_uuid() {
  C="89ab"
  for ((N=0;N<16;++N)); do
    B="$((RANDOM%256))"
    case "$N" in
      6)        printf '4%x' "$((B%16))" ;;
      8)        printf '%c%x' "${C:$RANDOM%${#C}:1}" "$((B%16))" ;;
      3|5|7|9)  printf '%02x-' "$B";;
      *)        printf '%02x' "$B";;
    esac
  done
  printf '\n'
}

function lb_read_sleep() {
  lb_check_args_num "${@}" 1
  read -rt "${1}" <> <(:) || :
}

function lb_bkr() {
  ((${#@} == 0)) && lb_fail "expected at least 1 arg but got 0"
  (nohup "$@" &>/dev/null &)
}

lb_bkr

Run a script in the background.

Parameters:
Name Type Description Default
None - - -
Examples:
bkr ./myscript.sh
Show source code in other
#!/usr/bin/env bash
: "${LIBBASH_DIR:?LIBBASH_DIR must be set. Please source libbash/init before other libraries.}"

#------------------------------ Global Variables ------------------------------

#------------------------------ Private Functions -----------------------------

#------------------------------ Public Functions ------------------------------

function lb_gen_uuid() {
  C="89ab"
  for ((N=0;N<16;++N)); do
    B="$((RANDOM%256))"
    case "$N" in
      6)        printf '4%x' "$((B%16))" ;;
      8)        printf '%c%x' "${C:$RANDOM%${#C}:1}" "$((B%16))" ;;
      3|5|7|9)  printf '%02x-' "$B";;
      *)        printf '%02x' "$B";;
    esac
  done
  printf '\n'
}

function lb_read_sleep() {
  lb_check_args_num "${@}" 1
  read -rt "${1}" <> <(:) || :
}

function lb_bkr() {
  ((${#@} == 0)) && lb_fail "expected at least 1 arg but got 0"
  (nohup "$@" &>/dev/null &)
}