Skip to main content
added 417 characters in body
Source Link

I would write it this way in a command line prompt. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

Here is a one liner:

~$ echo $text | tr ' ' '\n'

Output:

You
can
do
this,
but
the
newlines
will
be
embedded
in
the
variable,
so
it
won’t
be
a
single
line

Or, for a sorted output:

~$ echo $text | tr ' ' '\n' | sort

Output:

a
be
be
but
can
do
embedded
in
it
line
newlines
single
so
the
the
this,
variable,
will
won’t
You

I would write it this way in a command line prompt. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

I would write it this way in a command line prompt. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

Here is a one liner:

~$ echo $text | tr ' ' '\n'

Output:

You
can
do
this,
but
the
newlines
will
be
embedded
in
the
variable,
so
it
won’t
be
a
single
line

Or, for a sorted output:

~$ echo $text | tr ' ' '\n' | sort

Output:

a
be
be
but
can
do
embedded
in
it
line
newlines
single
so
the
the
this,
variable,
will
won’t
You

added 25 characters in body
Source Link

I would write it this way in a command line prompt. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

I would write it this way. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

I would write it this way in a command line prompt. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done
added 6 characters in body
Source Link

I would write it this way. It could be, of course, more compressed, but for clarity’s sake:

text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

array=$(echo $text | cut -d' ' -f 1-)

for x in ${array[@]}; do echo $x ; done

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done

I would write it this way. It could be, of course, more compressed, but for clarity’s sake:

text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

array=$(echo $text | cut -d' ' -f 1-)

for x in ${array[@]}; do echo $x ; done

I would write it this way. It could be, of course, more compressed, but for clarity’s sake:

~$ text='You can do this, but the newlines will be embedded in the variable, so it won’t be a single line'

~$ array=$(echo $text | cut -d' ' -f 1-)

~$ for x in ${array[@]}; do echo $x ; done
Rollback to Revision 1 - Edit approval overridden by post owner or moderator
Source Link
Loading
Source Link
Loading