1

I wrote an code which contain

str1 = "word1"
str2 = "word2"
str3 = "word3"

var1 = str("./e " + str1 + "/" + str2 + "/" + str3)

#NOW I NEED TO RUN A BASH COMMAND:

!cd bin && var1

#LIKE THIS: "cd bin && ./e str1/str2/str3"

How can I do this? Please help me, Thanks!

0

2 Answers 2

2

$var1 should work

str1 = "word1"
str2 = "word2"
str3 = "word3"

var1 = str("./e " + str1 + "/" + str2 + "/" + str3)

#NOW I NEED TO RUN A BASH COMMAND:

!cd bin && $var1

!echo $var1 #echos./e word1/word2/word3 whish you desired
Sign up to request clarification or add additional context in comments.

2 Comments

i get this error : /bin/bash: ./e: No such file or directory
final command is cd bin && ./e word1/word2/word3 if this is giving an error then there is problem with command are you sure you want to execute that ?this example just shows how you can you python variable to execute shell command in colab
0

You can use os module

 import os
 str1 = "word1"
 str2 = "word2"
 str3 = "word3"

 var1 = str("./e " + str1 + "/" + str2 + "/" + str3)

 os.system(f"!cd bin && {var1}")

1 Comment

that's working but i don't see the output of my ./e file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.