newbie: writing ksh shell problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting newbie: writing ksh shell problem
# 1  
Old 02-17-2010
newbie: writing ksh shell problem

my default profile is using ksh, I tried to write a simple scripts and I had issues, below is my scripts:

Code:
$ more if_num.ksh
USAGE="usage: if_num.ksh"
print -n "Enter two numbers: "
read x y
if ((x=y))
then
  print "You entered the same number twice."


when I tried to executed the script below is the errors:

Code:
$ ./if_num.ksh
./if_num.ksh: line 3: print: command not found


thanks comments I did wrong here?

Thanks,

Last edited by pludi; 02-17-2010 at 04:54 PM.. Reason: code tags, please...
# 2  
Old 02-17-2010
Quote:
Originally Posted by matthew00
thanks comments I did wrong here?
You assumed a suffix would suffice to tell the OS what interpreter to run.

The correct way is to have this as first line:
Code:
#! /bin/ksh

You are certainly using a Unix variant that uses bash as default shell and bash doesn't implement "print".
# 3  
Old 02-22-2010
can someone please tell me what I did wrong here?
# 4  
Old 02-22-2010
You can write:
Code:
echo $SHELL

to know what shell are you using.
'print' is a ksh sentence but it is not in bash, so probably our shell is bash.
# 5  
Old 02-22-2010
thanks
# 6  
Old 02-22-2010
Matthew,
As suggested above, your first line of script should have interpretter that needs to be used to evaluate shell script. It can be
Quote:
#!/bin/ksh (or) #!/bin/bash
Can you let me know output of below command?

Quote:
echo $SHELL
# 7  
Old 02-22-2010
echo $SHELL tells you which shell you're currently working in, as an interactive shell. It has no relationship to the first line in a script.

---------- Post updated at 05:52 AM ---------- Previous update was at 05:48 AM ----------

Code:
if ((x=y))
then
  print "You entered the same number twice."

should be:

Code:
if ((x==y))
then
  print "You entered the same number twice."
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with printf in UNIX KSH shell

Hi ALL, I am using SunOS 5.9 and KSH(bin/ksh) The problem am facing is error message diaplyed on screen printf: 12099415.79 not completely converted printf: + expected numeric value printf: 11898578.29 not completely converted When i try printing with The output is... (6 Replies)
Discussion started by: selvankj
6 Replies

2. Shell Programming and Scripting

Shell scripting newbie problem

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax, I'm guessing in the bolded line? ... (9 Replies)
Discussion started by: Tibor63
9 Replies

3. Shell Programming and Scripting

Problem with writing into a file through shell script

Hi all, I have a shell script which I use to login to the server from the client and then from the server I run a bunch of other scripts to complete my task. I am having problems with the script below- #!/bin/bash while read line do connections=`echo $line | cut -d " " -f 1` period=`echo... (3 Replies)
Discussion started by: joydeep4u
3 Replies

4. Shell Programming and Scripting

problem writing a simple c shell script

#!/bin/csh echo hello world this is what i got in a text file called ss1. i type "chmod 755 ss1.txt" to make it executable. then when i type ss1 or ss1.txt it says "ss1 command not found" what am i doing wrong? (19 Replies)
Discussion started by: pantelis
19 Replies

5. Web Development

Problems writing app that will communicate with gateway(newbie,last bit of project)

Hi all, Im writing an app that will contact a specified gateway and retrieve info onto our server and perform manipulations on it then return the result back to the gateway for further operations... But I'm a newbie and dont have much of an experience in network programming... Would like to... (0 Replies)
Discussion started by: wrapster
0 Replies

6. UNIX for Advanced & Expert Users

find command from shell scipt (ksh) problem

Hi experts, I have a simple shell script as follows. #!/bin/ksh FIND_STRING="\( -name 'testfile*.Z' -o -name 'DUMMY_*' \) " find /tmp -type f $FIND_STRING -print When I run this with ksh -x testscript, I get the following output. + FIND_STRING=\( -name 'testfile*.Z' -o -name... (6 Replies)
Discussion started by: kodermanna
6 Replies

7. Programming

Basic questions on writing a Unix Service (newbie help!)

Hi there. I've got 12 years experience writing C++ on Windows, and 3 years C# on Windows. Now my boss wants me to write a C++ app to run on Unix as a multithreaded 'service' (i.e. a program that runs with no user intervention). Some quick questions for The Experts: * Whats the best C++... (3 Replies)
Discussion started by: Rutland Gizz
3 Replies

8. Shell Programming and Scripting

Newbie problem with ksh script

Hi all, I have a directory have all of the .stat and .dat file : they are is a pipe separate flat file. Example: log-20061202.stat contain 1st line and last line of log-20061202.dat with record count of that day. Example: Total record = 240 Tom|02-12-2006|1600 W.Santa... (18 Replies)
Discussion started by: sabercats
18 Replies

9. Shell Programming and Scripting

KSH Script/FTP (NEWBIE)

I trying to write a ksh script (without the help of the Kermit libraries) which connects to a ftp server and checks if the file "KEI.done" exists. If the file exists it print "files is there" if it doesnt exist it prints "file is not there". (the print statements will later be replaced with code to... (2 Replies)
Discussion started by: mike509123
2 Replies

10. UNIX for Dummies Questions & Answers

help for newbie writing shell scripts

Hi, I have just started a Systems Programming course and am required to write a c shell script as part of it. I have little to no clue about unix. The spec states that the script can be run only once on each host by a user, but the script can be run on different hosts by the one user. ... (2 Replies)
Discussion started by: richgi
2 Replies
Login or Register to Ask a Question