Linux OS

Q1: How can I check if a variable is empty in bash?

In bash at least the following command tests if $var is empty:

if [[ -z "$var" ]]

The command man test is your friend.

Presuming bash:

var=""

if [[ -z "$var" ]]; then
 echo "not empty"
 else
 echo "empty"
 fi

Q2: How to assign a shell command output to a variable?

var=$(command-name-here)
var=$(command-name-here arg1)
var=$(/path/to/command)
var=$(/path/to/command arg1 arg2)

OR

var=command-name-here var=command-name-here arg1 var=/path/to/command var=/path/to/command arg1 arg2

Q3: A motion detection or video streaming utility on Linux

https://github.com/Motion-Project
A note on using motion on Raspberry Pi with the camera module (Rasp V3 with camera V2)
When you run motion, you always get a “unable to open video device” error and a grey screen
Solution:

You can access the camera board on /dev/video0 by running the command:

sudo modprobe bcm2835-v4l2

This will have to be run on every boot of the device. Or you can put modprobe bcm2835-v4l2 in /etc/rc.local to make it run on every boot automatically.

Q3: How to turn off font anti-alias in Ubuntu (to further change the default font, install “unity-tweak-tool”.
You can control the antialiasing of fonts in ~/.fonts.conf

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
</fontconfig>

 

Q5: The default font of Sublime Text on Windows) is Consolas and you might change it >preference>setting. You might also install it on Ubuntu and MacOS

Q6: How to create a soft or symbolic link?

I am installing p4v in /opt, but /usr/bin is on my path. Is it possible to create a soft or symbolic link for p4v from /opt to /usr/bin, so I can just type “p4v” since /usr/bin is in my path?

See man ln.

To create a symlink at /usr/bin/bar which references the original file /opt/foo, use:

ln -s /opt/foo /usr/bin/bar

You would need to apply the above command as root (i.e. with sudo).