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...
|
|
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 ?)
$
, root prompt#
, auxiliary prompt>
zsh: User prompt%
, root prompt#
, auxiliary prompt>
orpipe>
tcsh/csh: User prompt>
, root prompt#
, auxiliary prompt?
vms/dcl: User prompt$
, root prompt$
, auxiliary prompt_
Windows batch : User prompt[drive]>
, root prompt[drive]>
, auxiliary promptPlus?