Script no conditionals


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script no conditionals
# 1  
Old 09-29-2015
Script no conditionals

Hello, pro scripters, noob here,

I am complete noob in this and I have to write a program which:
Calculates the modulus of two numbers which the user enters with keyboard. Number interval 1-9. These two numbers that were entered and modulus which was calculated are stored in a separate file.
When the modulus equals 0, two previously entered numbers along the the calculated modulus (which is zero) are printed on the screen to the user.
The only constraint about the code - no conditionals should be used writing the program (if, while, etc.).

Please help me to do this. Cannot think of it myself.
I know little and we just started learning bash scripting so it should be simple I guess.
I tried to play with "sed" "grep" "read" commands without much success. Cannot fullfill all the requirements.
Please help. This is a very brief example what I have managed to do. :/

Code:
echo "Enter two numbers 1-9"
read -n 1 num1
echo $num1 > var.txt
read -n 1 num2
echo $num2 >> var.txt
expr $num1 % num2 >> var.txt


Last edited by Corona688; 09-29-2015 at 05:23 PM..
# 2  
Old 09-29-2015
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Gnu make: default values and conditionals

I need some help. I use variables and conditionals to build with or without specic libraries. I set USEAL ?= 1 # get value from cmd, defaults to 1 (see comment) the conditional is: ifeq ($(USEAL),1) LIBS = <any libs> else LIBS = endif Its amazing that this works when invoked... (4 Replies)
Discussion started by: dodona
4 Replies

2. Shell Programming and Scripting

Help with conditionals "if" :)

Hello friends, i have a problem with my code, i am writing a code in AIX, the code is: DIA=01 DIA_AUX=01 DIA_AUX=$(($DIA_AUX - 0)) MES=06 AŅO=`date +%y` AŅO=$(($AŅO + 2000)) H=0 cd /archive/datos proceso_sbs(){ cp co*$ARCHI /archive/scripts cd /archive/scripts ... (2 Replies)
Discussion started by: G412ud4
2 Replies

3. Shell Programming and Scripting

mysql help : query with 2 conditionals

Hi there, I have a table that stores multiple records for many different servers, each of which is timestamped ... I wanted to write a query that would enable me to only output the "latest" record (based on timestamp) for each "unique" server. So for example my main table looks like this ... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

4. Shell Programming and Scripting

Multiple conditionals in a while loop

Hi was wonderring about the syntax for the following peice of code: while ] ; do This is apparently incorrect. I want the loop to continue WHILE $life is not equal to zero or $mask is not equal to $word. Should ONE of these conditions fail to be met, loop should break out. Any ideas? ... (8 Replies)
Discussion started by: santeria
8 Replies

5. Shell Programming and Scripting

Log successful unix conditionals

Dears, Can anyone advise how to log successful conditionals (unix commands) from any ksh script? For example, the code is as follows: if <command> then Block1 of statements else Block2 of statements fi What needed exactly is to log "Block1 of statements" if its conditon is met.... (4 Replies)
Discussion started by: kadi
4 Replies

6. Shell Programming and Scripting

Using arrays with conditionals

Pardon the pseudo code below, but I'm wondering how I would do something along the lines of this... #!/bin/sh excludeList="A B" theItem="C" if then echo $theItem fi I know I could loop through the array and check against each value, but was wondering if there was an alternate way... (1 Reply)
Discussion started by: myndcraft
1 Replies

7. Shell Programming and Scripting

Multiple Conditionals

Yet another question. I want to make something like this: if ||&& then ... fi but that apparently is not right. I want either the first condition to be true OR the second AND third conditions to be true for the "then" to be processed. How can I do this? (1 Reply)
Discussion started by: jeriryan87
1 Replies

8. Shell Programming and Scripting

ideas for perl script - strings,conditionals..etc

I have a matrix , how do I compare all the elements of a column , lets say I want to check if the columns contain the alphabets "S","H","A","R","A","T". and not "X"s. Lets say matrix looks something like this .. SSSXSH HHXXHA AAXXAT RRRXRS AAXTAR TTTTTA I can hard code it where... (4 Replies)
Discussion started by: sharatz83
4 Replies
Login or Register to Ask a Question