Thread: Unix Task

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,467
    Rep Power
    1751
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep 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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,467
    Rep Power
    1751
    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.
    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep 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

IMN logo majestic logo threadwatch logo seochat tools logo