Gcc|C|bash|cat|sed|perl: Bad file descriptor

Guten Tag

Nach dem, mit ganz untenstehendem Bash-Script, einige *.h und ".C Dateien manipuliert wurden, erhalte ich folgenden Fehler beim Kompilieren mit gcc:

\*.h:22:27: calling fdopen: Bad file descriptor
gmake[1]: \*\*\* [\*.o] Error 1
gmake[1]: Leaving directory `/home/myself/cpp/cprog1'
make: \*\*\* [all] Error 2

Komischerweise tritt dieser Fehler bei Dateien auf, die nicht mit dem Script manipuliert wurden.

Woran kann das liegen?

Hier noch ein vorangehender Artikel dazu: http://www.wer-weiss-was.de/cgi-bin/forum/showarchiv…

Dank und Gruss
Olli

#!/bin/bash --init-file
#

#
# function add\_macro\_to\_macroh
#
function add\_macro\_to\_macroh()
{
 echo ''
 MACROH='/macro/macro.h'
 MACROH\_NEW=$MACROH.new

 checkout $MACROH \> /dev/null
 cat $MACROH | grep -v '#endif' \>& $MACROH\_NEW
 cat \>\> $MACROH\_NEW ]\s\*\n(?{push@p,pos})/g;
substr($\_,pop@p,0,qq{#include "macroh.h"\n}) $1
'
}

#
# function compile\_file
#
function compile\_file()
{
 COMPILE="${CC} ${CCOPTS} ${CINCLUDES} -c"

 echo 'compile' $1
 $COMPILE $1 \>& /dev/null
 if [[$? != 0]]
 then
 echo 'error while compiling' $1
 add\_macroh\_include\_to\_file $1
 echo 'compile again' $1
 $COMPILE $1 \>& /dev/null
 if [[$? != 0]]
 then
 echo 'error while compiling' $1
 revert $1 \>& /dev/null
 echo 'reverted' $1
 else
 echo 'compilation successful for' $1 
 fi
 else
 echo 'compilation successful for' $1
 fi
}

#
# function replace\_and\_compile
#
function replace\_and\_compile()
{
 for arg in "$@"; do
 echo ''
 #
 # search and replace and save changes
 #
 echo 'sed "s/strcpy/STRCPY/g"' $arg '\>' $arg.new
 sed 's/strcpy/STRCPY/g' $arg \> $arg.new
 #
 # move changes back to original file
 #
 echo 'mv' $arg.new $arg
 mv $arg.new $arg
 #
 # remove \*.new file
 #
 echo 'rm -f' $arg.new $arg
 rm -f $arg.new
 #
 # compile file
 #
 compile\_file $arg
 done
}

#
# Start
#
echo ''
echo 'starting replacement of strcpy with STRCPY'

# set environment
source ~/.bashrc
setmyenv

# 
# add the macro to macroh.h
#
add\_macro\_to\_macroh

#
# make files editable, replace string and compile
#
echo ''
echo 'checkout files'
checkout $(find\_in\_file strcpy h C | grep -v \_gui) \>& /dev/null
echo ''
echo 'start replacement of strcpy with STRCPY and compile'
replace\_and\_compile $(find\_in\_file strcpy h C | grep -v \_gui)

#
# End
#
echo ''
echo 'done'
echo 'please replace strcpy manualy in reverted files'
echo 'please submit files if everything is okay'

#
# revert where STRCPY, for convenience only
#
# echo ''
# echo 'Revert where STRCPY'
# revert $(find\_in\_file STRCPY h C | grep -v \_gui) \>& /dev/null

#
# revert where strcpy, for convenience only
#
# echo ''
# echo 'Revert where strcpy'
# revert $(find\_in\_file strcpy h C | grep -v \_gui) \>& /dev/null

#
# Exit Shell
#
exit

Guten Tag

Nach dem, mit ganz untenstehendem Bash-Script, einige *.h und
".C Dateien manipuliert wurden, erhalte ich folgenden Fehler
beim Kompilieren mit gcc:

*.h:22:27: calling fdopen: Bad file descriptor
gmake[1]: *** [*.o] Error 1
gmake[1]: Leaving directory `/home/myself/cpp/cprog1’
make: *** [all] Error 2

Komischerweise tritt dieser
Fehler bei Dateien auf, die nicht mit dem Script manipuliert
wurden.

Hi Olli,
ich habe mir zwar das Problem nicht im einzelnen angeschaut, aber mit der ‚-x‘ Option sollte man den Fehler eingrenzen können.

gruss
bernhard

Hallo

function add_macroh_include_to_file()
{
echo ‚add_macroh_include_to_file‘ $1
$ perl -i.bak -0777 -pe ’
my
@p;/#include\s+["]\s*\n(?{push@p,pos})/g;
substr($_,pop@p,0,qq{#include „macroh.h“\n}) $1

}

Bist Du sicher, dass Du ein $ vor dem Kommando
stehen hast? Was soll das machen?

(Obwohl das nicht Dein Problem lösen wird)

Grüße

CMБ

Die Lösung
Beim Kompilieren erzeugt gcc, aus welchem Grund auch immer, einige *.h.gch sowie *.C.bak bzw. *.h.bak Dateien. Lösche ich diese bevor ich das Programm kompiliere, funktioniert es fehlerfrei.

Keine Ahnung was da ganau passiert. Hauptsache ist, dass es jetzt funktioniert.

Danke für eure Hilfe.

Gruss
Olli