#!/bin/bash # Variables declare mac declare -a wol_com options name="$(basename "$0")" wolf_d="${HOME}/.wolf" wolf_host="${wolf_d}/${hostname}" # Arguments hostname="$1"; shift # Functions # Throw an error function error { >&2 echo -e "${name}: \033[1;31mERROR:\033[0m ${1:-No further details}"; shift exit "${1:-1}" } # Parse variable in options file function getvar { grep '^'"$1"' ' "$wolf_host" | cut -d ' ' -f 2 } # Parsing [[ -f $wolf_host ]] || error "\"${hostname}\": No such host" # Assign the options mac="$(getvar Mac)" ip="$(getvar IP)" port="$(getvar Port)" # Add options if necessary [[ -n $ip ]] && options+=(-i "$ip" ) [[ -n $port ]] && options+=(-p "$port") # Commands building # wol wol_com=( wol "$@" "${options[@]}" "$mac" ) # Debug #echo "${wol_com[@]}" #exit 0 # Execution set -xe "${wol_com[@]}"