From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: "Linux-C-Programming (E-mail)" <linux-c-programming@vger.kernel.org>
Subject: Re: Help in Shell script
Date: Tue, 11 May 2004 21:40:18 +0200 [thread overview]
Message-ID: <20040511194017.GC1912@lug-owl.de> (raw)
In-Reply-To: <000e01c43711$6c2a4de0$ae63d103@patni.com>
[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]
On Tue, 2004-05-11 10:05:43 +0530, Jogesh Kanojia <jogesh.kanojia@patni.com>
wrote in message <000e01c43711$6c2a4de0$ae63d103@patni.com>:
> Hi
>
> I want shell programs for the following:
> (a) To find the smallest number among the 3 numbers given.
function get_smallest_3() {
[ "$1" -lt "$2" -a "$1" -lt "$3" ] && echo "$1"
[ "$2" -lt "$1" -a "$2" -lt "$3" ] && echo "$2"
[ "$3" -lt "$1" -a "$3" -lt "$2" ] && echo "$2"
}
> (b) To check whether the given string is a palindrome or not.
function is_palindrome() {
if [ "$1" = "`echo "$1" | rev`" ]; then
return 0
else
return 1
fi
}
> (c) To sort the given list of numbers in descending order.
function sort_numbers() {
for nr in $*; do
echo $nr
done | sort --numeric-sort --reverse
}
> (d) To check, how many times a given substring occurs in a given main
> string.
That seems to be a bit more complicated. Don't have an idea ad hoc...
> (e) To find the factorial of a given number
function factorial() {
echo -e "define fact(x) { if (x <= 1) return (1); return (fact(x-1) * x); }\nfact(4)" | bc
}
Of course, there are superb books on shell programming and yes, I don't
like preparing other people's homework:)
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak!
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
prev parent reply other threads:[~2004-05-11 19:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-11 3:41 A C program to merge content of 2 binary tree Jogesh Kanojia
2004-05-11 4:35 ` Help in Shell script Jogesh Kanojia
2004-05-11 5:02 ` A C program to merge content of 2 binary tree, etc Jeff Woods
2004-05-11 5:47 ` Help in Shell script John T. Williams
2004-05-11 6:15 ` Jim Boedicker
2004-05-11 19:40 ` Jan-Benedict Glaw [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040511194017.GC1912@lug-owl.de \
--to=jbglaw@lug-owl.de \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.