I am running this piece of code:
annotate-output $((sed -E 's/^[ ]+//;' <<____COMMAND
sshfs
foo_user@fooserver.com:/sftp_folder
/var/sshfs.sandbox/server.com
-o
user=foo_user
,reconnect
,ServerAliveInterval=15
,ServerAliveCountMax=3
____COMMAND
) | sed -E -e ':a;N;$!ba;s/\n//g')
It's my (perhaps clumsy) attempt at having a generic way of achieving multiline in bash. Note that there is a trailing space whenever it is needed by the command I'm trying to split into multple lines:
sshfs
foo_user@fooserver.com:/sftp_folder
/var/sshfs.sandbox/server.com
-o
And no trailing spaces for options that have to be concatenated without an intervening blank space:
user=foo_user
,reconnect
,ServerAliveInterval=15
,ServerAliveCountMax=3
It works ok if I don't have quotes or double quotes anywhere. If I run this:
annotate-output $((sed -E 's/^[ ]+//;' <<____COMMAND
sshfs
foo_user@fooserver.com:/sftp_folder
"/var/sshfs.sandbox/server.com"
-o
user=foo_user
,reconnect
,ServerAliveInterval=15
,ServerAliveCountMax=3
____COMMAND
) | sed -E -e ':a;N;$!ba;s/\n//g')
I get:
fuse: bad mount point `"/var/sshfs.sandbox/server.com"': No such file or directory
It looks like the quotes are passed to sshfs as part of the "argument". Why?
Edit 1 (20170418 0739) [note this is now a separate question]:
I understand now why the quotes are preserved (ty Charles Duffy - see his answer below)
I modelled my solution after this answer. I need to apply sed twice, once for the leading space , and another one for the EOL, and that's why I end up using those comprehensions. PS: I have leading spaces, not leading tabs, hence the <<- marker that removes leading tabs is not useful
My original problem is that I want a boilerplate header/footer that I can paste in any script, and then just type the command enclosed in this header footer as if I didn't have to worry about indentation. I know I can solve the problem by assigning to a variable and then using the results later on, but I don't want that. I would like to be able to enter the newlined, indented command only in one place. Basically. with these characteristics:
- End of line spaces before the actual EOL preserved
- End of lines removed
- New line leading spaces removed
Is this possible?