#!/usr/bin/env bash __set_hostname() { new_hostname="${1}" if [ -z "$new_hostname" ]; then echo -n "Enter new hostname: " read -r response if [ -z "$response" ]; then echo "No hostname entered. Exiting..." return 1 fi new_hostname="$response" fi hostnamectl set-hostname "$new_hostname" sed -i "/^127\.0\.1\.1\s/c\127.0.1.1 $new_hostname" /etc/hosts echo "Hostname set to $new_hostname!" } __set_hostname "$1"