Results 1 to 6 of 6

Thread: Unix Shell programming Vs. C programming (which is better?)

  1. #1

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524

    Unhappy Unix Shell programming Vs. C programming (which is better?)

    While dealing with Unix text files, I found that a lot of people prefer file manipulation writing shell scripts rather than processing using C.

    My question is that, what is more efficient, shell programming or C programming?

    A C program, when run compiled, works as single process, but every shell command is a process, doesn't it mean that C code is more efficient?

    Thanks for any help :-)
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    C programming, definitely.

    Although it depends what you define as "efficient". If you want to do an operation on ten million rows of a text file, C will be much faster. However, it'll take you longer to write, so in total, a shell script might be faster.

    A lot of shell commands are implemented as shell builtins, so they won't spawn another process.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Also depends on the shell what is available or builtin.

    Yesterday, someone needed 380,000 addresses, RIGHT NOW.
    I wrote a perl script. Consider learning perl.

    Efficiency is in the eye of the beholder. Compiled C is faster, but for a one-up of 40 pages of text, who cares?. If it is run 1000 times a day, use perl, C, FORTRAN, whatever. Not script.

    Actually, real efficiency is cost-based. It it more expensive to have a user wait 5 seconds vs ten seconds or more efficeint to pay a programmer to work an extra hour? Depends on your shop.
    Are you running the smallest unix box avaialble with 500 users? Then pay the programmer.

  4. #4

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524
    Yes, I agree that efficiency depends on the particular problem.

    However, another advantage of using C is that, if the applications ever need to be ported to some different platform say, Windows form Unix, then changing C source code will be much easier than re-writing shell scripts.

    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not necessarily. A lot of things rely on POSIX features which Windows has a very poor implementation of.

    Plus, you can just run the shell program on Windows (Cygwin can do both of these, though).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Not everyone wants to install cygwin on their windows computer.

    Give the programmer a little more time and he should be able to write the app in a completly portable way.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width