Home Forums Kamanja Forums Problems & Solutions "Bad substitution" error in kamanja script on Ubuntu Linux (possibly all Debian

This topic contains 3 replies, has 3 voices, and was last updated by  Archived_User36 1 year, 8 months ago.

  • Author
    Posts
  • #13517 Reply

    Archived_User79
    Participant

    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

  • #13518 Reply

    Archived_User1
    Participant

    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.

  • #13519 Reply

    Archived_User79
    Participant

    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!

  • #13520 Reply

    Archived_User36
    Participant

    I’ve opened issue 965 https://github.com/ligaDATA/Kamanja/issues/965 to track this. Easy enough to fix.

Reply To: "Bad substitution" error in kamanja script on Ubuntu Linux (possibly all Debian
Your information: