Score:0

Translate bash command to xonsh

us flag

I have a .sh script i used which is no longer working. It checks if a Docker container exists by:

if [ -z "$(docker ps -q -a -f name=mujoco_roboy)" ]

This does not work in xonsh.

(docker ps -q -a -f name=mujoco_roboy) delivers some console output. How can i continue from that?

https://xon.sh/bash_to_xsh.html

Artur Meinild avatar
vn flag
Whoever voted to close, please retract your votes. This is a perfectly valid question about another Linux shell (Xonsh).
Score:0
vn flag

Xonsh uses a Python (not Bash) syntax, so an if statement is constructed in another way (unfortunately I'm not a Python expert).

But the basic structure is like this:

a = 200
b = 33
if b > a:
    print("b is greater than a")
elif a == b:
    print("a and b are equal")
else:
    print("a is greater than b")

Remember, in Python, the indentation is important and part of the language, instead of closing words in Bash (fi).

I found this Python reference, which hopefully can help.

Florian Schneider avatar
us flag
Thanks for the reply :) I code in python, this is also why I wanted to get xonsh in the first place But i do not know how to execute this in python. (docker ps -q -a -f name=mujoco_roboy) is a console command that asks docker for an output. I'd someho have to catch that and evaluate it.
Artur Meinild avatar
vn flag
Hmm I see. So actually this is about evaluating an expression, and not the if statement itself..
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.