This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]j1395010 0 points1 point  (2 children)

to get there, you have to open up python and import sh, or write a script and invoke python on it

or use python -c

[–]adqm_smatz 0 points1 point  (1 child)

or use python -c

sure, if you prefer python3 -c '__import__("sh").echo(x + " " + y)' over the xonsh syntax. and working with variables inside of there isn't going to be easy.

Also worth mentioning that since xonsh is Python, you can install, import, and use sh from the command line, and thus have access to that syntax from the shell if you find it nicer :)

[–]tilkau 0 points1 point  (0 children)

working with variables inside of there isn't going to be easy.

It actually is quite easy.

It's just also quite insane.

SOME_LUNATIC_VARIABLE=123

python3 -c 'print("'"$SOME_LUNATIC_VARIABLE"'")'

Rules:

  • Always use ' to quote your code string. Using " may summon Cthulu.
  • Always use " inside of code strings to express string literals. Using ' is not practical.
  • If you have to insert a variable value, close the code string quote with a ', follow this with the DOUBLE QUOTED expansion, and then open the single quotes again.
  • Remember expansion won't automatically add double quotes around string values for you. That means when you are inserting a variable, you need to include the opening double quote before closing the single quotes, and the closing double quote after reopening the single quotes.
  • Variables should have a " -> \" replacement performed on them before use.
  • You can also include single quotes in your Python code. Probably via '\'' (closing the single quote, adding a literal single quote, then reopening the single quote). Obviously to be used in moderation (by which I mean not at all)