How to add a directory to the PATH ubuntu?

Edit .bashrc in your home directory and add the following line:

export PATH="/path/to/dir:$PATH"

You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type

$ source ~/.bashrc

Using environment variables in Kubernetes deployment spec

I am concerned about pushing information such as passwords or IP addresses into remote Git repositories. Can I avoid this e.g. by making use of environment variables, e.g. with a deployment spec and actual deployment roughly as follows:

   type: LoadBalancer
   loadBalancerIP: ${SERVICE_ADDRESS}


export SERVICE_ADDRESS=<static-ip-address>
kubectl create -f Deployment.yaml

Obviously this specific syntax does not work yet. But is something like this possible and if so how?


In deploy.yml:

LoadbalancerIP: $LBIP

Then just create your env var and run kubectl like this:

export LBIP=""
envsubst < deploy.yml | kubectl apply -f -

envsubst is available in e.g. Ubuntu/Debian gettext package.


jenkins: bash script to backup all jobs

#! /bin/bash
    IFS=$(echo -en "\n\b")
    declare -i
    for i in $(java -jar jenkins-cli.jar -s http://localhost:8080 list-jobs  --username admin --password admin123);
    echo $i;
    java -jar jenkins-cli.jar -s http://localhost:8080 get-job --username admin --password admin123 ${i} > backup/${i}.xml;
    echo "done";

linux bash not reading last line

read needs the end of line to read the input

You can check if there is newline character in your file by executing:

Verify if you can see \n as the last character.

To overcome this you can either append newline to file:
echo >> FILENAME

You could try the following to ensure that the loop body executes if the final “line” isn’t newline terminated:

$ while read line || [ "$line" ]; do echo $line; done < FILENAME

bash: perform mathematical operations on strings

If VAR1 and VAR2 are strings having integer values like:


Then mathematical operations can be performed on it as below:
VAR3=$(echo “$VAR1 $VAR2” | awk ‘{print $1+$2}’)

OR you can also use:
VAR3=$(awk ‘{print $1+$2}’ <<<“$VAR1 $VAR2”)

bash: retrieve value of variable whose name is a variable

You can achieve that via:



this will give you value “someval”