[:ne binary operator expected

[:ne binary operator expected

In addition to the explanation here, this error pops up when comparing two values.
Pay attention either comparing is about comparing two strings or two numeric values.

As a reminder :

Numeric comparisons

val1 -eq val2
val1 -ne val2
val1 -ge val2
val1 -gt val2
val1 -le val2
val1 -lt val2

Strings comparisons

val1 = val2
val1 != val2
val1 val2
-n val1
-z val2

Further readings :



Enabling zenity notifications using cron

Making zenity notifications available using cron as a user is a bit tricky.

Here is the workaround to add to your scripts to make desktop notifications available.

DBUS=$(pgrep -ou $(whoami) mate)
DBUS="$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//')"

# Write a notification function
function Notif {
DBUS_SESSION_BUS_ADDRESS="$DBUS" zenity --notification --text="$1" --display=:0

# Test this notification function
Notif "your message"

Set up a cron job to test your function using crontab -e and let’s see the magic

bash : /usr/share/bash-completion/bash_completion : line 226 : syntax error near unexpected token ‘}’

While using bash auto-completion feature, you may have the following error :
“bash : /usr/share/bash-completion/bash_completion : line 226 : syntax error near unexpected token ‘}'”

Make sure not to have any bash keywords like ‘do’, ‘done’ as an alias in your own bashrc file.
Rename your alias and reload your updated bashrc file. Auto-completion works fine now in your bash shell.



Some bash tipsĀ (1)

Here are some bash tips that might be useful to you for a better and more efficient use of the bash shell.

The variable CDPATH

This variable expands the scope of the cd command.
By default, cd looks for a possible subdirectory in the current working directory.
Let us take an example :

fool@localhost:~$ cd cron

If CDPATH is not set, cd will look for a subdirectory named cron. If it does not exist, cd will look through the directories added to CDPATH. As we want to display the content of the directory /var/spool/cron, here is what we have to do :

fool@localhost:~$ export CDPATH=/var/spool/cron

Then, cd cron will work well and the current working directory will be /var/spool/cron

The bash builtin fc

fc displays a list of all the latest commands typed. It is like the command history.

To list the 16 lastest commands typed :

fool@localhost:~$ fc -l

To list a range of commands typed :

fool@localhost:~$ fc -l 495 501

The numbers 495 and 501 refers to the lines numbers displayed by the command history.

To reexecute the command number 495

fool@localhost:~$ fc -s 495

Unbinding jobs from your console

disown is a Bash builtin which allows you to run a job in the background and log off from your console. The job keeps running while the parent console is closed.

Syntax : disown job_id

To get the job_id, run the command jobs. You will see all the ids corresponding to the processes launched within your console.

nohup is an external command which does the same job.

Syntax : nohup your_command_line &

By default, nohup redirects stdout and stderr to a file named nohup.out.

Both can be used by non-root users.