* korn shell
@ 2000-11-14 5:00 tru64man
2000-11-14 5:00 ` Robert Mulley
0 siblings, 1 reply; 3+ messages in thread
From: tru64man @ 2000-11-14 5:00 UTC (permalink / raw)
I'm learning Korn here but I promise I will not flood this newsgroup
with trivial questions but I'm either lost or I'm an idiot. I'm reading
the book "Learning the Korn Shell" by Rosenblatt. On page 98 it
indicates a piece of code that I don't understand.
sort -nr $1 | head -${2:-10}
I know what sort and its options mean, the pipe sign, and the head
utility--no problem there. But I don't understand the last part
-${2:-10}
Could someone explain that part to me in somewhat elementary details?
thanks in advance.
Untru64Man
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: korn shell
2000-11-14 5:00 korn shell tru64man
@ 2000-11-14 5:00 ` Robert Mulley
2000-11-14 5:00 ` Lee A. Newcomb
0 siblings, 1 reply; 3+ messages in thread
From: Robert Mulley @ 2000-11-14 5:00 UTC (permalink / raw)
Hello
I believe it means either use the value of $2 or -10. ie if this is in a
script called "george" and you were to run:
./george sort_this_file 27
Then it would sort "sort_this_file" and display to first 27 lines otherwise
if you ran:
./george sort_this_file
it would sort "sort_this_file" and display the first 10 lines.
${2:-10} means either use the value of $2 or if $2 is NULL use the
"default" value -10.
Hope I've explained this to your satisfaction.
Robert Mulley
Unix Admin
tru64man@my-deja.com wrote:
> I'm learning Korn here but I promise I will not flood this newsgroup
> with trivial questions but I'm either lost or I'm an idiot. I'm reading
> the book "Learning the Korn Shell" by Rosenblatt. On page 98 it
> indicates a piece of code that I don't understand.
>
> sort -nr $1 | head -${2:-10}
>
> I know what sort and its options mean, the pipe sign, and the head
> utility--no problem there. But I don't understand the last part
> -${2:-10}
>
> Could someone explain that part to me in somewhat elementary details?
> thanks in advance.
>
> Untru64Man
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: korn shell
2000-11-14 5:00 ` Robert Mulley
@ 2000-11-14 5:00 ` Lee A. Newcomb
0 siblings, 0 replies; 3+ messages in thread
From: Lee A. Newcomb @ 2000-11-14 5:00 UTC (permalink / raw)
Your explanation is right as to what it does, but slightly
wrong in the description:
${2:-10}
means if $2 is not null, use its value; otherwise use '10'
(not '-10'). If -10 was used, 'sort -nr $1 | head -${2:-10}'
would be expanded to 'sort -nr $1 | head --10}' with an error
msg. like 'Badly formed number' displayed to stderr.
For more detail, do a 'man ksh' and look at the section
'Conditional Substitution' section, which describes the use
of ${var:-str}, ${var:=str}, ${var:?str}, ${var:+str}, ...
E.g.:
${ variable:-string }
If the variable is set and is not null, substitute the value of
variable in place of this expression. Otherwise, replace this
expression with the value of string.
Learning the Korn Shell is a great book. But make sure to check
your system's manpage for specific syntax def's.
Enjoy ksh,
-- lan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2000-11-14 5:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-14 5:00 korn shell tru64man
2000-11-14 5:00 ` Robert Mulley
2000-11-14 5:00 ` Lee A. Newcomb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox