This looks quite verbose to me, using the command substitution and echo …echo
:
# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;
# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )
Is there a cleaner (maybe faster ?) manner to assign a value to variable depending on some contition condition?