#!/bin/bash # Args come in the format of " --print-to-file ". # I need to extract and write all args to it. # Extract the file location (in an unknown position BUT it's 2 args after --print-to-file). for ((i = 1; i <= $#; i++)); do if [ "${!i}" == "--print-to-file" ]; then # Extract the file location. file_location="${@:i+2:1}" break fi done if [ "${!i}" == "--print-to-file" ]; then # Write all args to the file echo "$@" >"$file_location" else echo "$@" fi