"Bad substitution" error in kamanja script on Ubuntu Linux (possibly all Debian type Linux)

18 views
Skip to first unread message

kbill

unread,
Feb 15, 2016, 2:45:19 PM2/15/16
to kamanja
There is a problem when running on Ubuntu (possibly under any Debian type Linux).
The error is in $KAMANJA_HOME/bin/kamanja.
That script has a copyright header before the line "#!/usr/bin/env bash"
but in order to be executed, that line is required to be the first line in the script file.
When the file is modified to have that line as the first line, then it works correctly.

The problem is that on Ubuntu, if that line is not first, then the script is executed with the Bourne shell (sh) instead of the Basj shell (bash).
On Ubunutu (and possibly all Debian type systems), the Bourne shell on Ubuntu is a link to the "dash" shell, which does not support the "BASH_SOURCE[0]" construct,
(I found this out on Stack Overflow while debugging.)

This was using Kamanja 1.3.1 on Ubuntu 14.04 LTS with all the latest updates.

This can be demonstrated by creating a script that has one line: the ps command.
Then execute the script on Ubuntu using
sudo ./test.sh
The resulting output shows the Bourne shell (sh), not the Bash shell.

bill@bill-HP-255-G2-Notebook-PC:~$ sudo ./test.sh
[sudo] password for bill:
  PID TTY          TIME CMD
25116 pts/8    00:00:00 sudo
25117 pts/8    00:00:00 sh  ********** this shows that the Bourne shell is being used, not Bash ****************
25118 pts/8    00:00:00 ps

Donald

unread,
Feb 16, 2016, 11:06:48 AM2/16/16
to kam...@ligadata.com
What's happening is that your shell is "sh" because you have sued.  Linux defaults to running the script with whatever shell you are using and defaults to "sh" for root. The ps output shows that you have su'ed.  It slipped by because the testers here all use Bash for root.  You are right, however, that copyright notice needs to go and I am filing a bug report on it.  We need to explicitly invoke bash in that script.
Thanks.

Donald

kbill

unread,
Feb 17, 2016, 3:55:00 PM2/17/16
to kamanja
Thanks for the kind reply, Donald!
Of course, you could also just put the invocation of bash as the first line, and leave the copyright below that.

I've abandoned Ubuntu for now because I don't know if this situation exists in other Kamanja scripts.  So no I am using CentOS 7
Thanks again!

William Tarver

unread,
Feb 17, 2016, 4:07:55 PM2/17/16
to kbill, kamanja
I’ve opened issue 965 https://github.com/ligaDATA/Kamanja/issues/965 to track this. Easy enough to fix.
--
You received this message because you are subscribed to the Google Groups "kamanja" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kamanja+u...@ligadata.com.
To post to this group, send email to kam...@ligadata.com.
Visit this group at https://groups.google.com/a/ligadata.com/group/kamanja/.

Reply all
Reply to author
Forward
0 new messages