Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to print to stdout and save to variable (/dev/tty: No such device or address)? Edited

Deleted user Nov 14, 2017

I have the following Script, the Interpreter is set to Shell:

#!/bin/bash

RESULT=$(<cmd> | tee /dev/tty)
IMAGE_ID=$(python -c "<do sth. with $RESULT>")

I would like to store the result of cmd in RESULT and "print" it on screen (make it appear in the logs), but I am getting: tee: /dev/tty: No such device or address.

Any ideas how to achieve this?

I could just printf/echo $RESULT after the cmd finishes, but I would like to have "live" output.

2 answers

0 votes
robhit Atlassian Team Nov 15, 2017

Hi Tobias,

 

Not sure about the python stuff here, but if you want to store the command output in a variable using shell then:

var=`pwd`
echo $var

This way your variable "var1" will have the output of the command 'pwd' and you can later user this variable.

Hi Robhit,

Thanks for your reply. Please read my whole post again, I am looking for "live" output. Using the var solution will wait until the command finishes, before printing anything.

Thanks.

I just prefer python over awk to process strings. It doesn't matter for the question.

Ok got your requirement, sorry I missed the tty part

So, the error which you are getting is very weird because I tried using the tty in my bamboo but not hitting the same error but printing output to the logs is not working when using "tty /dev/tty" (I will look into this more to debug)

 

however, as a workaround, I used something like below to redirect the tty output to a temp file and then cat the file. I know it will create an unnecessary file but can't help it as of now need to debug more.

 

RESULT=$(echo "robhit saxena" | /usr/bin/tee test-file.txt)
cat test-file.txt
new_var=$(echo $RESULT | awk '{print $1}')
echo "new var is: "$new_var

 

Screenshots for the reference:

Screen Shot 0029-11-16 at 10.46.28 AM.png--------

--------Screen Shot 0029-11-16 at 10.46.14 AM.png------

------

0 votes

Interesting question - I'm not a shell scripting expert, but the following approach based on I/O Redirection to additional file descriptors seems to work well:

#!/bin/bash

exec 5>&1
RESULT=$(<cmd> | tee /dev/fd/5)
IMAGE_ID=$(python -c "<do sth. with $RESULT>")

 

Here's a test command to demonstrate it with Bamboo's Script task:

#!/bin/bash

exec 5>&1
RESULT=$(for i in `seq 1 8`; do ls -l && sleep 2; done | tee /dev/fd/5) 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

195 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you