Quantcast
Channel: Active questions tagged code-formatting - Meta Stack Overflow
Viewing all articles
Browse latest Browse all 180

How to properly format one liner shell scripts (bash/sh/zsh/batch/etc) in answers in a friendly way for the readers to copy & paste?

$
0
0

When adding a one liner shell script in an answer, what format/style do you think is better ?

For one liner bash/sh/ksh/zsh/etc., I'm formatting it like this:

$ echo -e "#include <stdio.h>\nint main(int nbargs, char *args[]) {> printf(\"Hello \\\n\");> }" | gcc -pipe -x c - -Wl,-oess2

The prompt signs ($ and >) correctly reflect the shell behavior for a one liner, but it's a pain in the neck for copy & paste.From my reader's point of view, the prompt signs are useful, it permits quick script type identification. But if you want to test it, you'll have to manually discard theses signs.

Trying to address this, I've tested many approaches without results yet:

$echo -e "#include <stdio.h>\nint main(int nbargs, char *args[]) {

>printf(\"Hello \\\n\");

>}" | gcc -pipe -x c - -Wl,-oess2

$ echo -e "#include <stdio.h>\nint main(int nbargs, char *args[]) {> printf("Hello \\n");> }" | gcc -pipe -x c - -Wl,-oess2

EDIT: My current best result, not very aesthetic...

    $
    >
    >
    echo -e '#include <stdio.h>\nint main(int nbargs, char *args[]) {
    printf("Hello \n");
    }'

There are two other questions that are somewhat related to this question :

What is the preferred way to format a long one-liner in an answer? from @22degrees

Should code in examples be copy-paste-able? [closed] from @Rakete1111

These questions are more specifically about one liner and prompt signs, but could be applied also to very long pipelined lines in scripts for the aesthetic aspect.

Is there a way on Stack Overflow to format one liner scripts in a way that will not harm reading and testing or to copy & paste ?

(If not, could we have a formatting feature to address this ?)


Viewing all articles
Browse latest Browse all 180

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>