Why does $ (cmd) return \n at the end of the string?

24 views
Skip to first unread message

Erick Tucto

unread,
Jun 22, 2018, 3:16:54 PM6/22/18
to xonsh
Hello ... it's a bit annoying to have to remember to use the strip () function to correct the returning string ... is there a simple way to avoid it ???



Pls help.
Auto Generated Inline Image 1

Gil Forsyth

unread,
Jun 22, 2018, 4:44:06 PM6/22/18
to xonsh
Hi Erick, 

There have been a few discussions around this in the past.  I recognize that it can take some getting used to, but we are capturing the output correctly, which does include the trailing newline unless you explicitly ask a function like `echo` to not use one.  

 ~ 🐚  $(echo 'hi')
'hi\n'
 
~ 🐚  $(echo -n 'hi')
'hi'

There's an open issue https://github.com/xonsh/xonsh/issues/2328 for discussion around adding the ability to strip only the final trailing newline.

Morten Enemark Lund

unread,
Jun 22, 2018, 5:01:06 PM6/22/18
to Erick Tucto, xonsh
Hi Erick 

Also, see the command substitution shorthand $@( ) 

/Morten


On Fri, 22 Jun 2018 at 21:16 Erick Tucto <erick...@outlook.com> wrote:
Hello ... it's a bit annoying to have to remember to use the strip () function to correct the returning string ... is there a simple way to avoid it ???

Auto Generated Inline Image 1

Pls help.

--
You received this message because you are subscribed to the Google Groups "xonsh" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xonsh+un...@googlegroups.com.
To post to this group, send email to xo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xonsh/8001619d-44e4-43b1-ac97-7e99ae1bc221%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages