• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what's the output for this shell script

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Case "$1" in # "" ) lines=50;; #*[!0-9]* echo "usage: `basename $0`
file-to-cleanup; exit $E_WRONGARGS;; #*) lines=$1;; #esac#

What's the output of the above? It looks simple, but could anyone tell me the exact result ?
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a line at the top, indicating for which shell it is written, like

#!/bin/bash
#!/bin/ksh

?
Did you remove some linebreaks?
 
Enge Chall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stefan Wagner:
Is there a line at the top, indicating for which shell it is written, like

#!/bin/bash
#!/bin/ksh

?
Did you remove some linebreaks?



It's ksh(#!/bin/ksh) and Assuming the case statement is getting executed what would be the output? is "#" is treated as comment here ? bit skeptical about it.
[ February 03, 2006: Message edited by: Enge Chall ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't speak ksh, but I like to puzzle
Here is the result of massive guessed translation to bash:
#!/bin/bash
E_WRONGARGS=42
lines=-1
case "$1" in
"" )
lines=50;;
*[!0-9]*)
echo "usage: " `basename $0` file-to-cleanup
exit $E_WRONGARGS;;
*)
lines=$1;;
esac
echo $lines
and here is the result:

Some problems:
'case' has to be lowercase in bash.
# introduces a comment
The echo statement contains an opening " which is never closed.
We don't know what is 'E_WRONGARGS' - probably a numeric errorcode, but where defined? A system-setting? Something ksh knows?

Well - you ask what's the output.
The output depends on the input.
If the 1. parameter ($1) is a positiv integral number, lines is this number.
If there is no parameter at all, lines is 50.
If the 1. parameter is something else, lines is undefined.

The output might be what you see on the screen, which is nothing, or the usage-message.
The output might be a return-code, which is either E_WRONGARGS or 0.

But since 'lines' is never used, I guess this is only part of a bigger script.

The usage-message is puzzling me.
It claims to call the script SCRIPTNAME file-to-cleanup.
But parameter 1 has to be an integer, so the filename has to be 17 i.e.?

conclusion:
I guess this is only a part of a script, but it is broken too, no matter what the rest of the script might be.
But I don't speak ksh and might be wrong.
reply
    Bookmark Topic Watch Topic
  • New Topic