Given a command that takes a single long string argument like:
mycommand -arg1 "very long string which does not fit on the screen"
is it possible to somehow split it in a way similar to how separate arguments can be split with \
.
I tried:
mycommand -arg1 "very \ long \ string \ which ..."
but this doesn't work.
mycommand
is an external command so cannot be modified to take single arguments.
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Using a backslash \ or « to print a bash multiline command If you're writing a multiline command for bash, then you must add a backslash (\) at the end of each line. For multiline comments, you have to use the HereDoc « tag.
You can assign your string to a variable like this:
long_arg="my very long string\ which does not fit\ on the screen"
Then just use the variable:
mycommand "$long_arg"
Within double quotes, a newline preceded by a backslash is removed. Note that all the other white space in the string is significant, i.e. it will be present in the variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With