Operating System - Linux
1753463 Members
4688 Online
108794 Solutions
New Discussion юеВ

Re: entering charcter or numerical value then checking

 
Mel Burslan
Honored Contributor

Re: entering charcter or numerical value then checking

Then maybe, instead of blindly posting questions in other UNIX platforms' forums, like HPUX here, you might want to try some linux forum. Huh ?
________________________________
UNIX because I majored in cryptology...
lcpdl87
Occasional Advisor

Re: entering charcter or numerical value then checking

and extra credit is not homework. it's something you choose to do if you more points to your grade and its OPTIONAL. it's not actual homework. homework is required to get the grade. I'm just trying to do this to boost my grade up alittle.
James R. Ferguson
Acclaimed Contributor

Re: entering charcter or numerical value then checking

Hi:

> Well, if I wasn't stuck, I wouldn't even bother checking this site for help. It's a forum, you post your problem and people help you out.

Yes, in principal. However, this community is intended to be for professionals dealing with professional problems, not for homework questions. You are more than welcome to lurk and learn.

Regards!


...JRF...
OldSchool
Honored Contributor

Re: entering charcter or numerical value then checking

"No, its extra credit, ..." that's homework

the version Mel posted works just fine w/ ksh and sh (after adding quotes around the []), has a few issues w/ echo in bash and dash

it appears that you missed some whitespace around the "%", but its hard to tell in the posts

original was:
...
result=$(($num % 2))
if [ $result -eq 0 ]
....


you posted:
...
the "result=$(($num %2))
if[$result -eq 0]
...
James R. Ferguson
Acclaimed Contributor

Re: entering charcter or numerical value then checking

Hi:

I meant to say "Yes, in principle". You see the _principal_ users here are professionals with professional needs, not students doing homework.

...JRF...

OldSchool
Honored Contributor

Re: entering charcter or numerical value then checking

there are a variety of shell tutorials available. parker's site is useful, as is shelldorado.

one thing I would caution you about is learning scripting on linux (ie. bash) and then attempting to use unix. the "linuxy" gnu extensions that you will come to expect simply won't be there.

ksh tends to port well from unix to linux, and visa versa.
Dennis Handly
Acclaimed Contributor

Re: entering charcter or numerical value then checking

>I'm working with Linux 10

(I'll ask the moderators to move it there with your other thread.)

>OldSchool: original was:
>result=$(($num % 2))

There is no need to use "$" within (( )) or $(( )).
(( result = num % 2 ))

In fact, you can replace the original by:
if (( number % 2 == 0 )); then

ghostdog74
Occasional Advisor

Re: entering charcter or numerical value then checking

#!/bin/bash
awk 'BEGIN{
while(1){
printf "Enter a numerical number: "
getline number < "/dev/stdin"
if (number+0==number){
print "yes, a number"
break
}else{
print "no, not a number. Enter again"
}
}
print "number is " number
if ( number %2 == 0 ){
print "Number "number" is even"
}else{
print "Number "number" is odd"
}
}'
lcpdl87
Occasional Advisor

Re: entering charcter or numerical value then checking

I tested that. That makes it say there's no file or directory for the file.
ghostdog74
Occasional Advisor

Re: entering charcter or numerical value then checking

it works fine for me.