I want to separate a long path to multiple lines, like this:
cd foo1/foo2/foo3/foo4/bar
to
cd foo1\
   foo2\
   foo3\
   foo4\
   bar
You can separate a long command into multiple lines by using backslashes, but you would need to preserve the forward-slashes and omit the leading spaces:
cd foo1\
/foo2\
/foo3\
/foo4\
/bar
The backslashes are a line-continuation marker; when bash sees them, it incorporates the next line as if it was continued at the backslash of the current line. As a result, you couldn't use leading spaces on those subsequent lines, since they'd become spaces on the current line, creating a "too many arguments" error.
You could do this with an array but the cd command looks a bit complicated:
path=(
    foo1
    foo2
    foo3
    foo4
    bar
)
cd "$(IFS=/; echo "${path[*]}")"
Array literals allow for arbitrary whitespace.
"$*" and "${array[*]}" forms, when in double quotes, join all the elements into a single string, joined by the first character of the IFS variable. IFS is, by default, "space tab newline", so I redefine it in the subshell to hold the directory separator.
                
                declare -p path. "${path[*]}" joins the elements into a single string using /, the first character of IFS.
                
                
/) automatically?