Bash – How to return a value in a function

Here are some ways to return a value in a function in a Bash script:

1. Strings

function foo()
    echo "true"


if [ "$retval" == "true" ];
     echo "true"

2. Exit status

function foo()
    return 0


if [ $retval == 0 ];
     echo "okay"

3. Shared variable


function foo()


if [ "$retval" == 0 ]
     echo "okay"

Adapted from:


TeamCity agent doesn’t show the application window when a build is run

If you are running TeamCity agent as a service in Windows you probably noticed that you cannot see any application window that your build agent is running.

You don’t see any window because, for security reasons, the latest versions of Windows runs services in Session0 and not Session1. Sometimes you need to see it, specially if you running tests. If you need to run TeamCity agent on Session1 and not Session0 and be able to see what is going on without having to access Session0 you shouldn’t be running your TeamCity agent as a service.

In the installation wizard, you should untick the option to install the agent as a service:


After installing it, you need to configure the build agent to be run automatically when the machine starts. You need to add a shortcut to “<installation path>\bin\agent.bat start” in “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup” for all users.


DevOps for offline products

It is much easier to talk about DevOps in companies in which their products are online but in companies in which most applications, if not all, run in the customer side and we don’t have access to them is very challenging.

One of the most important values of DevOps is to have a “Ops Ready” application. A “Ops Ready” application means that Operation team should be able to detect problems in it easily.

A “Ops Ready” application has a good way to be monitored after deployment so you can anticipate problems and avoid hearing from customers. A very good way is to have some kind of heartbeat in all system components which sends information about the system and the machine it is running on. In the end, you should figure a problem out instead of being told about it.

Although a very good idea, it is very hard (or impossible) to have this kind of heartbeat system when the application normally  runs offline. It is harder but we still need to have some way to track the problems down.

The solution for this problem depends on the type of application you are working on but you should create some kind of offline monitoring mechanism and have this data stored somewhere and maybe sent to you once a connection is available. Supporting an application if this kind of mechanism is much easier.

You should take privacy into account but this is a subject for a different post.


IncrediBuild tries to upgrade Visual Studio solution

After using IncrediBuild for some time, one day it started showing me some errors while trying to upgrade a Visual Studio solution file. The solution had not been changes at all. After some work trying to figure something out I ended up finding a workaround: reset Visual Studio user settings.


You can reset your setting by opening CMD in the location of devenv.exe of the Visual Studio version and running the command:

devenv /resetuserdata general

After that, Incredibuild doesn’t think the solution needs to be upgraded and it builds the solution normally.

I hope it helps someone.

Running a Linux application using Cygwin/X

Sometimes I need to run a X11 application from Microsoft Windows and the way I normally do that is by using Cygwin/X.

Installing Cygwin/X

Run Cygwin setup and select the ‘xinit’ package from the ‘X11’ category. You can find the setup file in Cygwin page. You will need SSH as well if you don’t have it installed yet. Cygwin also provides a package for SSH.

Running the application

After installing Cygwin/X, follow the following steps:

  1. Start “XWin Server”
  2. Start XTerm by going to “X applications menu/System Tools/XTerm” for your Cygwin/X Server in the system tray.
  3. XTerm will open (white screen). Now, you should connect to the Linux server you want to use via SSH using -XY to establish your secure shell connection with X11 support:
    It is easier to establish proper X11 forwarding using the XTerm window because it sets a DISPLAY variable for you automatically, which is needed by the X Window System.echo $DISPLAYIf you would like to establish the connection from your main Cygwin shell instead, you will have to set your DISPLAY manually.  Either of these commands will do that.export DISPLAY=:0
    export DISPLAY=:0:0
  4. Open the application you want to run. You might want to run “xlogo” to test the connection first and following screen will be displayed: