LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (http://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   time command gives error for SBU in Binutils (http://www.linuxquestions.org/questions/linux-from-scratch-13/time-command-gives-error-for-sbu-in-binutils-823277/)

na5m 07-31-2010 03:56 PM

time command gives error for SBU in Binutils
 
Code:

$ time { ../binutils-2.20/configure --target=$LFS_TGT --prefix=/tools --disable-nls --disable-werror && make && make install; }
bash: syntax error near unexpected token `}'
$ time -V
GNU time 1.7
$ type time
time is /usr/bin/time

I'm reading LFS Stable 6.6. Maybe the time command
method in the Binutils section needs to be updated.
I'm using PCLinuxOS 2010.07.

After googling, I found that this works:
Code:

$ time bash -c " foo && bar && blah ; "
Any thoughts?

carltm 07-31-2010 04:53 PM

The problem is not with time, it is bash that is sending the error.

My guess is that bash is expecting a command after the semicolon,
and is finding the "}" instead. Try removing the semicolon.

na5m 08-01-2010 02:13 AM

Without the trailing semicolon, I get this error:
Code:

$ time { command }
time: cannot run {: No such file or directory

So, it looks like with the semicolon, bash raises an error.
Without the semicolon, time raises an error.

druuna 08-01-2010 03:47 AM

Hi,

There are 2 versions of the time command and they work differently:

1) A bash internal, which is used in the LFS example ($ type time -> time is a shell keyword)
2) An external time command, which you seem to use ($ type time -> time is /usr/bin/time)

The order in which bash looks for them: first the internal command, if not present the external one.

I find it a bit curious that you do not have the internal bash time command. Looks like PCLinuxOS 2010.07 is different that way.

Did you check the vii. Host System Requirements and is PCLinuxOS 2010.07 compliant for building LFS?

Anyway, this does explain the discrepancy.

Hope this helps.

na5m 08-01-2010 01:23 PM

I've since discovered:
PCLinuxOS 2010.07 does meet the host system requirements.
However, the time command shown in the LFS book is the bash
builtin command, not /usr/bin/time.
So, if your bash doesn't have time built into it, then the SBU value's command will fail.
I think the book should be updated to warn users of this possibility.
I'm guessing that most distros have a bash with time built into it.
PCLinuxOS 2010.07 isn't one of them:
Code:

$ builtin time
bash: builtin: time: not a shell builtin

EDIT:
Things have changed: I downloaded and burned lfslivecd-x86-6.3-r2160.iso.
I booted into it and got:
Code:

# which time
which: no time in (/bin:/usr/bin:/sbin:/usr/sbin)
# builtin time
-bash: builtin: time: not a shell builtin
# type cd
cd is a shell builtin
# type time
time is a shell keyword

Talk about complicated and confusing!
So I guess that time can either be
  1. a system file
  2. a shell builtin
  3. a shell keyword

druuna 08-01-2010 02:56 PM

Hi,

Quote:

So I guess that time can either be
a system file
a shell builtin
a shell keyword
Time is, when it comes down to it a builtin, but...... The time command is listed in the official Bash documentation as a keyword ("reserved word") and will show up as such.

The time command can be an executable (/usr/bin/time) and/or a bash keyword.

BTW: Time is one of the bash defaults, if you compile it normally it will be included. So I guess that PCLinuxOS should mention this (and other?) exclusion, it would be undoable for LFS to mention all the exceptions to the defaults other distro's created (be it for good or bad).

In general these external commands (time being one, pwd being another) are there for specific reasons. They work slightly different or have some other features. You also need to call them explicitly:
pwd for normal use (the bash keyword that is),
/bin/pwd to use the external executable.

Hope this helps.

na5m 08-01-2010 05:55 PM

Thank you, druuna. It's hard to imagine that time could be a keyword,
like while, for, do, etc. Anyway, I guess we've beat this dead horse
long enough :)

PS- this site spilled some light on the topic:
http://tldp.org/LDP/abs/html/internal.html

carltm 08-01-2010 07:23 PM

Anyway, going back to the original problem:

Quote:

$ time { command }
time: cannot run {: No such file or directory
Try using parentheses instead of curly braces.

na5m 08-01-2010 10:17 PM

Code:

$ /usr/bin/time ( ls )
bash: syntax error near unexpected token `ls'


druuna 08-02-2010 02:41 PM

@carltm:
Quote:

Anyway, going back to the original problem:
Which problem :)

I though na5m already has a working solution: time bash -c " foo && bar && blah ; " (see post #1).
And I told why the two are different.


All times are GMT -5. The time now is 03:41 AM.