Bash file line continuation


















Perl Given Perl's strong Unix roots, you might think it would recognize this convention also or at least have some funky variable you could set or unset. Got something to add? Send me email. Wed Jun 21 BigDumbDInosaur For some strange reason, I've seldom used continuation characters to break up overly-long lines. I'd even argue it offers more control instead of spitting out whatever line ending. But really, the original poster is asking about using echo and the question is tagged with Bash.

Paul Hodges Paul Hodges IMO this is was best, easiest answer to keep my code readable each line being a variable holding a string itself. I need to export this value and you can't export arrays.

DKebler Your comment contains multiple syntax errors. It's hard to guess what you mean, or take the surrounding advice too seriously. See also useless use of echo. It works with echo and string arguments, but it doesn't work with other things, like variable assignment.

Though the question wasn't about variables, using echo was only an example. Lance E Sloan. LanceESloan That's because of the unquoted space, though, so it's really a separate issue. If you remove the space before the backslash, this works with assigments, too.

Bash is a time waster, that's for sure. This probably doesn't really answer your question but you might find it useful anyway. The first command creates the script that's displayed by the second command. The third command makes that script executable.

The fourth command provides a usage example. Well-intentioned- and possibly even useful- though this may be, the OP asked for advice on basic bash syntax, and you gave him a python function definition which uses OO paradigms, exceptional flow control, and imports.

Further, you called an executable as part of a string interpolation- something that a person asking this kind of question would definitely not have seen yet in bash.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. Improve this question. Open the way Open the way See additional discussion at stackoverflow. Add a comment. Active Oldest Votes. Improve this answer. Paolo Guillaume Guillaume RyanM The backslash has to be the very last character before the end of line character.

George Yeah. The problem appears to be that the script was given to me by someone that uses windows. A quick dos2unix fixed it : — RyanM. Show 1 more comment. Is there a formal list of such situations, where a command is implicitly continued onto the next line? It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search.

I have been reading "The Linux command line book" and I have encountered this line continuation character and I am confused why do we use it with this find command:.

That find command is a single simple shell command, which just takes a number of distinct arguments, and has a structure of its own. Those arguments are just not meaningful to the shell, so it doesn't know there's e. The whole command could be written on a single line, it would just be harder to read. Without the line continuations, find would run on playground with the default printing action, and then the shell would try to run the command without arguments or, the command -type in a subshell, if you were to remove the escape from the , too :.

On the other hand, the if compound statement is part of the shell syntax, and the shell knows what parts there are to expect. After the then there must be a command, and eventually an else or fi. The whole structure could also be written on a single line, but then we'd need to add semicolons before the else and the fi.

In the same way echo foo; echo bar requires to semicolon or a newline to be taken as two commands.



0コメント

  • 1000 / 1000