Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialReign Anu
1,537 PointsConcatenating Scripts
When it comes to running scripts in the console can I concatenate a script, if its printed output is a string, with another string. If so how would I go about doing so?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsRunning in the console is a Linux shell environment. Running a basic script is straightforward:
$ python my_script.py
Some string output from script
Notice that there aren't quotes around the output. This is because output is assumed to regular text.
Now the fun part! In the console, the bash
shell command line allows you to use the results of on command inside another command by wrapping a command in backticks: ` (usually found to the left of the 1 key)
Continuing the previous example:
$ python my_script1.py
String output1
$ python my_script2.py
Other string output2
$ echo `python my_script1.py` `python my_script2.py`
String output1 Other string output2
# or concatenate a string with script output
$ echo "I got this output: " `python my_script1.py`
I got this output: String output1