How do i finish this script?

February 16, 2011 at 09:31:29
Specs: Windows XP
Hi

I have a problem regarding Unix scripts (bash [I'm writing the script with gedit], but I dont really get the task or how to make the solution.

I have to use gcc, but do not know what I should do with it ...

________________________________
Here is the task:

Copy all. c files of the directory as a parameter passed to a new directory to be created ~/tmp/work

Discuss the possibility of error ("tmp" not here, "work" not here, one of them is not a directory; "work" is not empty) with appropriate error messages.

Compile the copied files.

Test whether the programs are executed.

________________________________

This is what I already got:


gcc 1.c -> to compile

for testing:

test -x a.out (if not, then a message appears like: "problem")

i

<pre>
f [ ! -d $HOME/tmp ]
then
echo tmp doesn't exist or it isn't a directory
fi

if [ ! -d $HOME/tmp/work ]
then
echo work doesn't exist or it isn't a directory
fi

if [ ! -e $HOME/tmp/work/* ]
then
echo work isn't empty
fi

mkdir -p $HOME/tmp/work
cp $1/*.c $HOME/tmp/work
cd $HOME/tmp/work
for I in *. c, Thu
gcc *\.c
...

I do not know the code or what i have to write after gcc *\.c
I hope someone can help me.


See More: How do i finish this script?

Report •

#1
February 16, 2011 at 10:11:20
First, the general form of the for loop is:

for I in *.c
do
   .
   .
done

Second, I don't understand what you are trying to do. Are all the "C" source files part of one executable program in the directory?

Or is each "C" source file an individual, stand alone program?


Report •

#2
February 16, 2011 at 10:17:31
there are severel *.c files

like 1.c abc.c testprogram.c

and i have to compile every *.c file and test, if it is executeable


Report •

#3
February 16, 2011 at 10:54:25
k, now i got this


#! /bin/bash

if [ ! -d $HOME/tmp ]

then

echo tmp existiert nicht oder kein Verzeichniss

fi

if [ ! -d $HOME/tmp/work ]

then

echo work existiert nicht oder kein Verzeichniss

fi

if [ ! -e $HOME/tmp/work/* ]

then

echo work nicht leer

fi

mkdir -p $HOME/tmp/work

cp $HOME/*.c $HOME/tmp/work

cd $HOME/tmp/work

i=1

for i in *.c;

do

gcc *\.c

done

but this error message appears:

./test: line 13: [: too many arguments
dokument1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
tx2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
tx2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
tx2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input


Report •

Related Solutions

#4
February 16, 2011 at 12:21:09
Assuming all your "C" source has a main function, you have to compile each program individually. I guess you could use a.out the default executable name, but I choose to give each executable a name. For example, the testprogram. compiled executable would be testprogram.oc:

#!/bin/bash

# Untested in Linux, not near my Linux box - run using Solaris cc compiler 
for I in *.c
do
   E=$(basename $I .c)
   cc $I -o $E.oc
   if [ -x $E.oc ]
   then
      echo "$E.oc is executable"
   fi
done


Report •

#5
February 16, 2011 at 12:32:57
Thanks man!!!

It worked :)

dokument1.oc is executable
dokument2.oc is executable
tx2.oc is executable

but i know why the error came...

all my *.c files were empty, so that's why it didn't work


Report •

#6
February 16, 2011 at 12:40:45
thread can be closed

Report •

#7
February 16, 2011 at 15:52:45
I guess I need to contact Justin about a way to mark posts as solved or closed.

"The era of big government is over," said Clinton 1996


Report •

Ask Question