I'm having a strange error when I'm trying to start the make process for LFS using the LiveCD SVN Trunk. When I go to run make it gives me;

$ make
/bin/sh: 1: [: -ne: unexpected operator
-e Missing gawk on host!
Please install gawk and re-run 'make'.
make: *** [test-host] Error 1

but I already have gawk installed and I can see this when I run version-check.sh script.

bash, version 4.3.11(1)-release
/bin/sh -> /bin/dash
Binutils: (GNU Binutils for Ubuntu) 2.24
bison++ Version 1.21.9-1, adapted from GNU bison by coetmeur@icdc.fr
/usr/bin/yacc -> /usr/bin/bison++.yacc
bzip2,  Version 1.0.6, 6-Sept-2010.
Coreutils:  8.21
diff (GNU diffutils) 3.3
find (GNU findutils) 4.4.2
GNU Awk 4.0.1
/usr/bin/awk -> /usr/bin/gawk
gcc (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
g++ (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
(Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19
grep (GNU grep) 2.16
gzip 1.6
Linux version 3.13.0-37-generic (buildd@kapok) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014
m4 (GNU M4) 1.4.17
GNU Make 3.81
GNU patch 2.7.1
Perl version='5.18.2';
sed (GNU sed) 4.2.2
tar (GNU tar) 1.27.1
xz (XZ Utils) 5.1.0alpha
g++ compilation OK
libgmp.la: not found
libmpfr.la: not found
libmpc.la: not found

even in my path directory I see that gawk is indeed installed.

$ ls -la /usr/bin | grep awk
lrwxrwxrwx  1 root    root          21 Mar  4 17:36 awk -> /etc/alternatives/awk
-rwxr-xr-x  1 root    root      538224 Jul  3  2013 dgawk
-rwxr-xr-x  1 root    root         950 Mar 16  2012 dpkg-awk
-rwxr-xr-x  1 root    root      441512 Jul  3  2013 gawk
-rwxr-xr-x  1 root    root        3188 Jul  3  2013 igawk
-rwxr-xr-x  1 root    root      117768 Mar 24  2014 mawk
lrwxrwxrwx  1 root    root          22 Mar  4 17:36 nawk -> /etc/alternatives/nawk
-rwxr-xr-x  1 root    root      445608 Jul  3  2013 pgawk

I don't get why it claims that it's not installed when it is installed. Why is this happening?

  • 1
    Your problem isn't that gawk isn't installed, it's that the test to detect gawk is buggy (or failing because you're running it in an unexpected environment). Post that makefile, or a link to it. – Gilles Jun 29 '15 at 22:40
  • I see, well the SVN Trunk can be viewed here, the development files all on that page. - wiki.linuxfromscratch.org/livecd/browser#trunk – user91679 Jun 30 '15 at 0:54

Looks like this code is where the problem lies:

        @if [ $$EUID -ne 0 ] ; then \
         echo "You must be logged in as root." && exit 1 ; fi
        @if ! type -p gawk >/dev/null 2>&1 ; then \
         echo -e "Missing gawk on host!\nPlease install gawk and re-run 'make'." && exit 1 ; fi

When the first if … is executed, the variable EUID is not set, so the command [ -ne 0 ] is executed, and this isn't valid syntax for the [ utility. When the second if … is executed, the command type -p gawk is executed, and it returns a failed status even though gawk does exist, indicating that either PATH isn't set properly or the type command doesn't support the -p option. (Spoiler: it's the latter.) And the error message has -e at the beginning, showing that echo doesn't recognize -e as an option.

This makefile relies on bash features: EUID, echo -e and type -p are bash features. Your system's sh is dash, not bash (dash is the default on Debian and check-version.sh confirms that /bin/sh is dash). Dash is a leaner, faster shell than bash; it doesn't have much more than what POSIX requires, and that doesn't include EUID or type -p. I haven't gone through the makefile but there are probably many more places where it requires bash.

Since the makefile requires bash, it should contain a line with SHELL = bash. In the absence of such a line, tell make to use bash as the shell for all commands: run

make SHELL=/bin/bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy