Error with "multiplication table" in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error with "multiplication table" in shell script
# 1  
Old 03-22-2010
Error with "multiplication table" in shell script

Code:
#!/bin/sh
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$number * $i = expr $number \* $i"
done



I am not getting the output for this multiplication table.

Last edited by pludi; 03-22-2010 at 04:59 AM.. Reason: code tags, please...
# 2  
Old 03-22-2010
Try this code : -

Code:
$ cat mul.sh
#!/bin/sh
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$number * $i = `expr $number \* $i`"
done
$


Last edited by pludi; 03-22-2010 at 04:59 AM.. Reason: code tags, please...
kandi.reddy
# 3  
Old 03-22-2010
Its working

Hi, Thanks a lot ,
actually i forgot to put `.
# 4  
Old 03-22-2010
You are welcome...

No Issues
kandi.reddy
# 5  
Old 03-22-2010
Quote:
Originally Posted by kandi.reddy
Try this code : -

Code:
$ cat mul.sh
#!/bin/sh
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$number * $i = `expr $number \* $i`"
done
$


There's no need for the external command, expr:
Code:
$
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
  echo "$number * $i = $(( $number * $i ))"
done
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. HP-UX

HP-UX: Shell Script giving " 0^J30: Syntax error"

Hi All, We are getting a very unique error while running a shell script on HP-UX box. Can somebody help in this regards? The shell script is working fine on linux/solaris box. Error: ++++++++++++++++++++++++ $/test.sh ./test.sh: 0^J30: Syntax error $ ++++++++++++++++++++++++ TIA.... (16 Replies)
Discussion started by: vai_sh
16 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. HP-UX

Need to identify the process/app which is triggering the error "vmunix: file: table is full"

Hi, I'm seeing the error vmunix: file: table is full in syslog.log. Although changing the value of the kernel parameter nfile would make this error go away, how would I identify which process/application in the server is triggering this error? The server is a HP-UX B.11.11. Thanks in advance! (1 Reply)
Discussion started by: enchogas
1 Replies

5. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

9. Shell Programming and Scripting

"else" unmatched error in shell script.

Friends I have pasted a script below d08083: cat tests #!/bin/ksh if then rm -r Last-Previous mv Previous Last-Previous mv Current Previous mkdir Current #cd Current mv $1 Current else cd Current mv "$1\$2" Current\*\ fi (4 Replies)
Discussion started by: Renjesh
4 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question