error in ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in ksh script
# 1  
Old 10-15-2008
error in ksh script

Hi,

i am facing an error in the following script in the korn shell but in bash it is working , can any help me to convert the below script to korn shell script without errors.

echo 123.4566 | bc -l | awk -F '.' '{ print $1; exit; }'

Thanks in advance
kamal
# 2  
Old 10-15-2008
Error in ksh script

I got 123 as an answer, no error. Smilie
I ran it on HP-UX in a script starting with #! /usr/bin/ksh
Ans also on the commandline were echo $SHELL was the ksh.

What error do you get? Smilie
# 3  
Old 10-15-2008
here is the error that i got

Quote:
Originally Posted by rene_metaal
I got 123 as an answer, no error. Smilie
I ran it on HP-UX in a script starting with #! /usr/bin/ksh
Ans also on the commandline were echo $SHELL was the ksh.

What error do you get? Smilie

the form me it has shown was ,
awk: syntax error near line 1
awk: bailing out near line 1
# 4  
Old 10-15-2008
Code:
$ echo 123.4566 | bc -l | awk -F '.' '{ print $1; exit; }'
awk: syntax error near line 1
awk: bailing out near line 1

$ echo 123.4566 | bc -l | awk -F. '{ print $1 }'
123

And, of course, all you need is:

Code:
$ typeset -i n=123.4566;print $n
123

# 5  
Old 10-15-2008
Quote:
Originally Posted by radoulov
Code:
$ echo 123.4566 | bc -l | awk -F '.' '{ print $1; exit; }'
awk: syntax error near line 1
awk: bailing out near line 1

$ echo 123.4566 | bc -l | awk -F. '{ print $1 }'
123

And, of course, all you need is:

Code:
$ typeset -i n=123.4566;print $n
123

how to round it to near value....
if it is 123.999, then how to make it 124 using scripting in ksh
# 6  
Old 10-15-2008
It seems you're using ksh88 (a Korn shell implementation that does not support floating point arithmetic).
So you can try something like this:
Code:
$ unset n
$ n=123.333                                                             
$ _n=${n#*.};((${_n%${_n#?}}>=5))&&print $((${n%.*}+1))||print ${n%.*}
123
$ n=123.666                                                             
$ _n=${n#*.};((${_n%${_n#?}}>=5))&&print $((${n%.*}+1))||print ${n%.*}
124


Last edited by radoulov; 10-15-2008 at 02:26 PM.. Reason: corrected ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error in ksh script: missing right bracket

I have no idea how to write ksh script, but i'm really in need of help with this. I using fedora 30 and in attempt of runnig attached script i getting those errors, i solved first error by removing excess bracket, but i do not know what should i do with other. Pls sorry for trash post. (8 Replies)
Discussion started by: NullPtr
8 Replies

2. Shell Programming and Scripting

ksh Script - Syntax error `done' unexpected

Hello, I am working on my first ksh script to review daily reports. The script uses different functions to check different types of reports in csv format. A control file gets read in with information regarding the report, other info, and the function to use. When I run the script I get the... (4 Replies)
Discussion started by: bot9196
4 Replies

3. Shell Programming and Scripting

Please review error routines in my ksh script

The script distributes files from an AIX server using iether ftp or sftp depending on the constraint of the destination server. I am interested in having the error checking routine critically reviewed. I will only include an excerpt from the script concerning error trapping: (where $FTP_OUT is the... (7 Replies)
Discussion started by: peleton
7 Replies

4. Red Hat

KSH script help needed ( nice error trap routine ?)

I am running a script that runs a loop and executes a command on ${i} until the end of the for loop. From time to time the command generates an error ( which is good) for example ERROR0005: How can I trap the error and send an email echoing the ${i} variable in the loop and the error ? ... (2 Replies)
Discussion started by: pcpinkerton
2 Replies

5. Shell Programming and Scripting

Ksh Shell Script Error

Hi, While running below code i am getting error as below 0403-004 Specify a parameter with this command. Please look it below code and let me know about if condition. Code is As below #!/usr/bin/ksh Infa_Src_Dir=$DIR/SrcFiles/pp Load_Info_Lst_Path=$DIR/SrcFiles/pp... (1 Reply)
Discussion started by: samadhanpatil
1 Replies

6. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

7. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

8. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

9. Shell Programming and Scripting

Shell script run error ksh: not found

Hi All, I am trying to run a script to FTP files from one UNIX server to another UNIX server. Actually I can able to FTP file successfully by manually or paste whole script at prompt. But when I am trying to run script it is giving error. Please let me know the cause. #!/bin/sh... (3 Replies)
Discussion started by: nz80qy
3 Replies

10. Shell Programming and Scripting

ssh command in ksh script encounters permission error

I've created a script and copied it to another server and try to execute it at the same time but I'm getting a permission error. I'm logged on as root and I gave the file 777 permission when I created it, but I can't run it remotely via ssh command because of permission issue. Any ideas? ... (5 Replies)
Discussion started by: pdtak
5 Replies
Login or Register to Ask a Question