LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2008, 06:35 AM   #1
dpraveenit
LQ Newbie
 
Registered: Jun 2008
Posts: 1

Rep: Reputation: 0
How to execute ksh files in Fedora Core 4?


I am new to linux. I have installed Fedora Core(2.6.11-1.1369_FC4) in my pc. I have written a simple ksh script and stored it in welcome.ksh .
I am trying to execute welcome.ksh file by typing "welcome.ksh" in terminal, but not sure why it throws an error saying "command not found".

The file "welcome.ksh":

echo "Welcome to Unix"

Let me know how to execute the script in terminal.

Thanks in Advance.
 
Old 06-21-2008, 07:26 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by dpraveenit View Post
I am trying to execute welcome.ksh file by typing "welcome.ksh" in terminal, but not sure why it throws an error saying "command not found".
When you run an executable on the command line, the shell searches for it in the directories listed in the PATH environment variable. If the executable isn't found in one of those directories, well, the obvious happens. You can run executables that aren't in your PATH by giving the full path to them and if the executable is in the current directory, you can use "./executable", where "executable" needs to be substituted with the name of the executable. The . is short for the current directory, so using "./executable" is giving the full path to the executable.

Also, you probably want to install a newer version of Fedora, since 4 is out of date and probably no longer supported. The latest version is 9.

Last edited by Nylex; 06-21-2008 at 07:29 AM.
 
Old 06-21-2008, 11:39 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
In addition to the PATH information given...

The source code for a shell program may have an extension; e.g., .sh or, in your case, .ksh (although that's overkill). An executable shell program does not need nor should it particularly have an extension -- the standard in UNIX-based systems is that executable programs, AKA commands and utilities, just do not have an extension. The idea is that you develop source code, saving source code files with a given extension and then create the executable with the make utility; e.g., if you have a file, prog.sh and type make prog the make utility will copy prog.sh to prog then change mode of prog to 755 with the command chmod 755 prog. Then you can simply type prog on the command line and hit the carriage return and prog will execute.

If you look around the system, you will find that there are a large number of shell programs that you use constantly without even realizing that the utilities you're using are just... well, shell programs. You can see this by, for example
Code:
file /usr/bin/* | grep -i shell
(There should be 400+ and not a one of them has a .sh extension).

Now, after all that, you can turn your welcome.ksh into an executable program with
Code:
cp welcome.ksh welcome
chmod 755 welcome
and put welcome on a PATH where everyone can get do it; e.g., /usr/local/bin or something similar (or as suggested above). You can't use make to do this because make doesn't know what .ksh means (it does, however, know what to do with the standard .sh extension).

And, last but not least, when you write a Korn shell program, be sure and make the first line of the file be
Code:
#!/bin/ksh
so that it will execute with the Korn shell rather than whatever shell a use is using.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract gz files on fedora Core 4 Jacko123 Linux - Newbie 1 08-28-2007 03:45 AM
How to extract rar files in fedora core 6 me4linux Linux - Software 3 04-24-2007 04:09 PM
What is the best way to parsing, handle files ksh, perl, c++ richikiki Programming 7 07-06-2006 09:18 AM
KSH: syncing three files the hard way ReefShark Programming 1 07-31-2005 11:56 AM
Accessing Old Files Through Fedora Core md2bn08 Linux - Newbie 1 05-06-2004 03:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration