I'm using parameter substitution with an error message, such as ${var1:?'some message'}
. I've incorporated a multi-line error message. Presently, it only functions properly when enclosed within single quotes, with line breaks inserted using the Enter key. Is there a clever way to allow acceptance of multiple lines, saved separately?
I'm just curious about exploring this. Please avoid suggesting alternative syntax involving if statements unless it's directly relevant.
Cases:
works: single quote
needed=${1:?'first error line
second error line
third error line'}
not working: call another string variable
usage_message='Please use this script by providing the following arguments:
1: <e.g user name>
2: <e.g run script>
3: <e.g something else>'
username=${1:?$usage_message}
run_script_path=${2:?$usage_message}
where_to_save=${3:?$usage_message}
not working: call a function
function get_message {
echo -e "first line \nsecond line\nthird line"
# or
# printf "first line \nsecond line\nthird line"
}
needed=${1:? $(get_message)}
Other discussion about parameter substitution: https://stackoverflow.com/a/77772942/13413319
username=${1:?"$usage_message"}
– steeldriver Feb 20 '24 at 01:47