The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> UNIX Help
|
Unix Task
Discuss Unix Task in the UNIX Help forum on Dev Shed. Unix Task UNIX Help forum discussing the Unix Operating System and all variants including Irix, Solarix, and AIX. Unix was designed as a true multi-user operating system.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 16th, 2011, 10:18 AM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 3
Time spent in forums: 3 h 2 m 32 sec
Reputation Power: 0
|
|
|
Unix Script
Hi, i have got this source code
Code:
#! /bin/bash
if [ ! -d $HOME/tmp ]
then
echo tmp doesn't exist or is no directory
fi
if [ ! -d $HOME/tmp/work ]
then
echo work doesn't exist or is no directory
fi
if [ ! -e $HOME/tmp/work/* ]
then
echo work is not empty
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
I hope someone can help me
|

February 16th, 2011, 01:44 PM
|
|
|
Not tested, but ... try this
Code:
#! /bin/bash
# Make sure the directory and sub-directories exist
mkdir -p $HOME/tmp/work
# Tell us if directory has something in it
count_files=$(ls -1 $HOME/tmp/work | wc -l | awk '{print $1}')
if [ $count -ne 0 ]
then
echo work nicht leer
fi
# Copy all .c files from home to temp directory
cp $HOME/*.c $HOME/tmp/work
# Go there and compile all .c files
cd $HOME/tmp/work
gcc *.c
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|

February 16th, 2011, 01:58 PM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 3
Time spent in forums: 3 h 2 m 32 sec
Reputation Power: 0
|
|
EDIT: THREAD CAN BE CLOSED!
The problem was, that i just filled the copied files (the *.c files) with a right source code, but not the original files. That's why it has always overwritten the other file and the file was empty.
_________________________________
K, now i got the full source code, which is also working... but not really this great :/
Code:
#! /bin/bash
if [ ! -d $HOME/tmp ]
then
echo tmp doesn't exist or it is no directory
fi
if [ ! -d $HOME/tmp/work ]
then
echo work doesn't exist or it is no directory
fi
if [ ! -e $HOME/tmp/work/ ]
then
echo work not empty
fi
mkdir -p $HOME/tmp/work
cp $HOME/*.c $HOME/tmp/work
cd $HOME/tmp/work
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
error:
Code:
dokument1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument1.oc is executable
dokument2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
dokument2.oc is executable
tx2.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input
tx2.oc is executable
it says it's executable, but i also says, that the *.c file has got an error
|

February 17th, 2011, 01:29 AM
|
|
|
|
I don't know C, bu I'd assume those are compiler/linker errors, suggesting that there's a syntax/semantic error within your .c files.
|

February 17th, 2011, 09:14 AM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 3
Time spent in forums: 3 h 2 m 32 sec
Reputation Power: 0
|
|
you are right
like i said, the content of the file was something like this:
test .c file
or
this is my first .c file, which i made with the bash
...these were not my files. My teacher gave us these files, but ye... not working .c files... great!
Anyway, problem solved and everything is working fine
Thanks guys
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|