Archive for the ‘bash’ Category

GNU Makefile setting env variables

January 12, 2019 Leave a comment

Exporting env variables in Makefiles. The issue was that the environment variables were not visible across different targets. I needed the same env vars to be seen in both target1 and target2 below.

Export the variables outside the target, eg at the top of the file.


export VALUE1
export VALUE2

    echo $VALUE1

    echo $VALUE2


Categories: bash, Interesting Tags: ,

Useful Linux Command Line Bash Shortcuts You Should Know

November 21, 2018 Leave a comment

In this article, we will share a number of Bash command-line shortcuts useful for any Linux user. These shortcuts allow you to easily and in a fast manner, perform certain activities such as accessing and running previously executed commands, opening an editor, editing/deleting/changing text on the command line, moving the cursor, controlling processes etc. on the command line.

Although this article will mostly benefit Linux beginners getting their way around with command line basics, those with intermediate skills and advanced users might also find it practically helpful. We will group the bash keyboard shortcuts according to categories as follows.

Categories: bash, Interesting

docker: Error response from daemon…

August 22, 2018 Leave a comment

I was getting this error.

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused “exec: \”telnet\”: executable file not found in $PATH”: unknown.

$ docker run --name greeter -d --expose 5000 alpine /bin/sh -c "echo Welcome stranger | nc -lp 5000"
$ docker exec greeter ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:02
          inet addr:  Bcast:  Mask:
          RX packets:9 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:758 (758.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:  Mask:
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
$ docker run alpine telnet 5000
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"telnet\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled
$ docker run -it alpine /bin/sh
/ # telnet 5000
/bin/sh: telnet: not found

This error means that whatever I am trying to run does not exist. So my options are to install telnet in the container or use a different command like `nc`.

Categories: bash Tags:

port forwarding

August 17, 2018 Leave a comment


You want to access a site with a particular IP. Eg google maps only allows a set of IPs to access. So running code from a vagrant box then accessing from the host is not so straight forward.

Went with using ssh

$ ssh -nNT -L 3000:localhost:3000 vagrant@ -p 2222

So on the host I can access a service running on a vagrant box ( via localhost:3000

Categories: bash

find command examples

October 24, 2017 Leave a comment

I needed to clean up after running tests

Using find

$ tree
├── bin
│   └── hello
├── hello
│   ├──
│   └──
├── requirements.txt
└── tests

3 directories, 7 files
$ python3 test                                            
running test
running egg_info
creating hello.egg-info
writing dependency_links to hello.egg-info/dependency_links.txt
writing top-level names to hello.egg-info/top_level.txt
writing hello.egg-info/PKG-INFO
writing manifest file 'hello.egg-info/SOURCES.txt'
reading manifest file 'hello.egg-info/SOURCES.txt'
writing manifest file 'hello.egg-info/SOURCES.txt'
running build_ext
test_print_hello (tests.test_hello.TestHello) ... ok

Ran 1 test in 0.014s


Now more files are created.

$ tree
├── bin
│   └── hello
├── hello
│   ├──
│   ├──
│   └── __pycache__
│       ├── hello.cpython-35.pyc
│       └── __init__.cpython-35.pyc
├── hello.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   └── top_level.txt
├── requirements.txt
└── tests
    ├── __pycache__
    │   ├── __init__.cpython-35.pyc
    │   └── test_hello.cpython-35.pyc

6 directories, 15 files

To delete the *.pyc files and the __pycache__ and hello.egg-info folders, run the following commands.

$ find . -type d -name "hello.egg-info" | xargs rm -rf
$ find . -type d -name "__pycache__" | xargs rm -rf
$ find . -name "*.pyc" | xargs rm -f


$ find --version                                                   
find (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2) 


Categories: bash Tags: ,


August 1, 2017 Leave a comment

Well this was more like an irritant. I have a portforwarding script that I manually start. I just got tired of doing that and moved it to an upstart task.

Added the following job for upstart to handle.

$ less /etc/init/portforward.conf
description     "Portforward 3141 to devpi server"

author      "Vagrant"

start on runlevel [2345]
stop on runlevel [!2345]

    cd /home/vagrant

    export SSHPASS="vagrant"
    sshpass -e ssh -nNL 3141: -o ConnectTimeout=10 -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@
end script
$ # Check the syntax
$ init-checkconf /etc/init/portforward.conf
$ # Start the job
$ sudo service portforward start


Categories: bash Tags: ,

A Powerline style prompt for your shell

July 23, 2017 Leave a comment

For a hassle free powerline like shell. Works with bash and zsh.

* Shows some important details about the git/svn/hg/fossil branch (see below)
* Changes color if the last command exited with a failure code
* If you’re too deep into a directory tree, shortens the displayed path with an ellipsis
* Shows the current Python virtualenv environment
* It’s easy to customize and extend. See below for details.

Categories: bash, zsh Tags: