If you want to do this in a reliable way that works for every possible command line argument (values ββwith spaces, values ββwith newlines, values ββwith literal quotation marks, values ββthat cannot be printed, values ββwith glob characters, etc.), it gets a little more interesting.
To write to a file, specify an array of arguments:
printf '%s\0' "${arguments[@]}" >file
... replace with "argument one" , "argument two" , etc., if necessary.
To read from this file and use its contents (in bash, ksh93 or another recent shell with arrays):
declare -a args=() while IFS='' read -r -d '' item; do args+=( "$item" ) done <file run_your_command "${args[@]}"
To read from this file and use its contents (in a shell without arrays, note that this will overwrite your local list of command line arguments, and thus it is best done inside the function, so that you overwrite the function with arguments, not the global list) :
set -- while IFS='' read -r -d '' item; do set -- "$@" "$item" done <file run_your_command "$@"
Note that -d (which allows you to use a different line terminator) is an extension other than POSIX, and a shell without arrays cannot support it either. In this case, you may need to use a language without a shell to convert NUL-restricted content to an eval safe form:
quoted_list() { ## Works with either Python 2.x or 3.x python -c ' import sys, pipes, shlex quote = pipes.quote if hasattr(pipes, "quote") else shlex.quote print(" ".join([quote(s) for s in sys.stdin.read().split("\0")][:-1])) ' } eval "set -- $(quoted_list <file)" run_your_command "$@"