little problem with a simple shell program i made.

This is a discussion on little problem with a simple shell program i made. within the Linux Programming forums, part of the Platform Specific Boards category; unix api naturally: say you fork your terminal application and execute "ls -l" in the child, why won't the color ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    81

    little problem with a simple shell program i made.

    unix api naturally:

    say you fork your terminal application and execute "ls -l" in the child, why won't the color and the formatting etc... appear in the output? I've got it just printing the plaintext output.

    Is there a way to do it through perhaps piping?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by keira View Post
    unix api naturally:

    say you fork your terminal application and execute "ls -l" in the child, why won't the color and the formatting etc... appear in the output? I've got it just printing the plaintext output.
    You probably have an alias set up for ls which turns on color output. When you exec ls, pass it the "--color=yes" option to enable color.

    Type 'alias' in your shell, you'll probably see an alias there.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    --color=auto, which ls is usually mapped to with alias, is a better idea, because it doesn't try to print colours when the output isn't a console -- when the output is redirected to a file, for example. (Otherwise, with --color=yes, you'll probably get lots of ANSI escape sequences.) But maybe --color=yes is what you want, I don't know.

    BTW, you can see the currently set aliases by typing "alias". And you can set them like so:
    Code:
    $ alias gcc='gcc -W -Wall'
    $ alias
    gcc='gcc -W -Wall'
    ls='ls --color=auto'
    $
    (I made up that output, alias might actually print things slightly differently.)

    alias is built into your shell, which is probably bash. Just in case you're curious.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple socket client/server program
    By spencer88 in forum C Programming
    Replies: 6
    Last Post: 05-05-2009, 11:05 PM
  2. Problem with a simple program
    By Salgat in forum C Programming
    Replies: 10
    Last Post: 06-15-2006, 05:57 PM
  3. Help with simple program
    By nik2007 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2006, 08:54 AM
  4. problem with simple program
    By mabufo in forum C++ Programming
    Replies: 3
    Last Post: 01-29-2006, 12:39 AM
  5. Problem with Simple C Program
    By djtomr941 in forum C Programming
    Replies: 22
    Last Post: 12-21-2004, 12:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21