#!/bin/bash aim=0 depth=0 horizontal=0 while read current; do case "$current" in "down "*) current_tmp=${current/down /} aim=$((aim+current_tmp)) ;; "up "*) current_tmp=${current/up /} aim=$((aim-current_tmp)) ;; "forward "*) current_tmp=${current/forward /} horizontal=$((horizontal+current_tmp)) depth=$((depth+aim*current_tmp)) ;; esac done echo $((depth*horizontal))