Thread: what does echo $status means??

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    what does echo $status means??

    can someone explain this?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    "echo" prints the value of its arguments to its output, which is usually the screen. "$status" evaluates to the value of the variable "status". Here's a bash example.
    Code:
    $ status=something
    $ echo Hello, World!
    Hello, World!
    $ echo $status
    something
    $ status='something else'
    $ echo $status
    something else
    $
    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.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so if my main function returns one calling echo $status directly after that will print 1
    ??

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so when will echo $status return 1 when called?

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    so if my main function returns one calling echo $status directly after that will print 1
    ??
    It would, if $status were set -- however, I think the variable you're looking for is $?, in bash at least.
    $? Expands to the exit status of the most recently executed foreground pipeline.
    From http://tldp.org/LDP/Bash-Beginners-G...ml#table_03_03
    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.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    how do i set $status??

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by -EquinoX- View Post
    so if my main function returns one calling echo $status directly after that will print 1
    ??
    If you are on an operating system/in a shell where the status environment variable is defined, then yes.

    Edit: Google says $status is a C-shell variable; bash uses $? as pointed out below. We may seem smart, but we don't actually have a clue what shell you're running.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    because I typed in echo $status and it doesn't print anything, just a blank line

    I did the echo $status just directly after I run the main

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, try $?. If that doesn't work, tell us what shell you are using.
    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.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I am using a korn shell

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by -EquinoX- View Post
    I am using a korn shell
    According to Google, the korn shell uses $? to hold the last return value.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Directories and files using dirent.h
    By totalnewbie in forum C Programming
    Replies: 6
    Last Post: 11-19-2008, 05:10 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. A breakthrough
    By loopy in forum Linux Programming
    Replies: 4
    Last Post: 11-26-2003, 06:46 PM
  4. C-Shell Scripting.. Help!
    By denizengt in forum Tech Board
    Replies: 3
    Last Post: 10-29-2003, 01:37 PM
  5. echo command
    By Billing in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-31-2001, 08:38 PM