Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Bash scirpt help (msys)? (http://www.programmingforums.org/showthread.php?t=11653)

iradic Oct 21st, 2006 12:44 PM

Bash scirpt help (msys)?
 
I wrote a script to generate makefiles...

And it works but not always :)

Here is some info output...

This shouldn't happen:
:

$ mage.sh -u *.c > Makefile
Makefile -> /tmp/.mage.sh.432.mak
1
new file: dlist.c
1
new file: filter.c
1
new file: getaline.c
1
new file: hash.c
1
new file: main.c
1
new file: memdbg.c
1
new file: parser.c


This is ok:
:

$ mage.sh -u *.c           
Makefile -> /tmp/.mage.sh.1120.mak
0
old file: dlist.c
0
old file: filter.c
0
old file: getaline.c
0
old file: hash.c
0
old file: main.c
0
old file: memdbg.c
0
old file: parser.c


And this is the guilty part of script (I think):
:

UpdateNew () {
    # updates include only cc stuff
    for file in $(echo "$1" | sed 's/:/ /g') ; do
        if [ ! -r "$file" ]; then
                Warn "Could not open - '$file'"
                continue
        fi
        if $(grep -q '^'${file%.*}'[$](OBJ):' "${tmp}.mak"); then
          echo $? 1>&2
          Notify "old file: $file"
          old="$old$file:"
        else
          echo $? 1>&2
          Notify "new file: $file"
          new="$new$file:"
        fi
    done
    MkDepend "$old"
    EmitCC "$new"
}


Note that script works when not redirecting???
How should I fix this?

Thanks

Ooops, I just noticed that when not redirecting to Makefile (which is copied in the first place) everything works... Anyway can I fix this behavior?

iradic Oct 21st, 2006 2:57 PM

1 Attachment(s)
And here is some more "funny" stuff...

Bash debug output:

:

$ cp copy Makefile

$ mage.sh -u *.c > new
Makefile -> /tmp/_mage.sh.1144.mak
++ grep -q '^dlist[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: dlist.c
++ grep -q '^filter[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: filter.c
++ grep -q '^getaline[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: getaline.c
++ grep -q '^hash[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 1
1
+ set +o xtrace
new file: hash.c
++ grep -q '^main[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: main.c
++ grep -q '^memdbg[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: memdbg.c
++ grep -q '^parser[$](OBJ):' /tmp/_mage.sh.1144.mak
+ echo 0
0
+ set +o xtrace
old file: parser.c

$ cp copy Makefile

$ mage.sh -u *.c > Makefile
Makefile -> /tmp/_mage.sh.996.mak
++ grep -q '^dlist[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: dlist.c
++ grep -q '^filter[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: filter.c
++ grep -q '^getaline[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: getaline.c
++ grep -q '^hash[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: hash.c
++ grep -q '^main[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: main.c
++ grep -q '^memdbg[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: memdbg.c
++ grep -q '^parser[$](OBJ):' /tmp/_mage.sh.996.mak
+ echo 1
1
+ set +o xtrace
new file: parser.c


I have put script in the attachment.

iradic Oct 22nd, 2006 12:08 PM

I figured it out...

Makefile gets truncated if redirected to it before script is run (and Makefile copied)...

Bye


All times are GMT -5. The time now is 10:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC