1

A function from a larger script:

function lipo {
OUTDIR=$SDK_DIR/lib/$CONFIG
mkdir -p $OUTDIR
for LIBNAME in $SDK_DIR/lib/$CONFIG-iphoneos/lib*
do
    BASELIBNAME=`basename $LIBNAME`
    OUTLIB=$OUTDIR/$BASELIBNAME
    echo lipo $BASELIBNAME for $CONFIG
    lipo $SDK_DIR/lib/$CONFIG-iphoneos/$BASELIBNAME $SDK_DIR/lib/$CONFIG-iphonesimulator/$BASELIBNAME -create -output $OUTLIB
done
}

The target directory has a few files in it, in fact here is a real example: enter image description here

When I run this function, this happens:

enter image description here

It just very quickly loops forever on the first file... (whole screen fills up in under 1s) the echo is being run but nothing else - this lipo operation takes a second or so so for it to loop dozens of times a second, it's not running. But no errors are given.

If I run the command on a single file by hand, it seems to work fine - or if I mess it up I get an error. So two questions really...

  1. Why is only the echo being run?
  2. Regardless if the command succeeds, how can the loop keep repeating the first file in the directory forever?

1 Answer 1

4

The answer is recursion1.

You are effectively doing:

foo() {
  echo something
  foo
}

You probably want to change the function name to something else.


Alternatively, you could suppress shell function lookup by saying:

command lipo $SDK_DIR/lib/$CONFIG-iphoneos/$BASELIBNAME $SDK_DIR/lib/$CONFIG-iphonesimulator/$BASELIBNAME -create -output $OUTLIB

instead of

lipo $SDK_DIR/lib/$CONFIG-iphoneos/$BASELIBNAME $SDK_DIR/lib/$CONFIG-iphonesimulator/$BASELIBNAME -create -output $OUTLIB

in which case you could keep the existing function name as is.

Quoting help command:

Runs COMMAND with ARGS suppressing  shell function lookup, or display
information about the specified COMMANDs.  Can be used to invoke commands
on disk when a function with the same name exists.

1. recursion, n: See recursion.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh drat, you're right! I've been banging my head against various build scripts for two days and gone "code blind"! Originally the lipo command was something else, I changed it and never even noticed this problem. How embarrassing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.