LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to execute ksh files in Fedora Core 4? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-execute-ksh-files-in-fedora-core-4-a-650693/)

dpraveenit 06-21-2008 05:35 AM

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.

Nylex 06-21-2008 06:26 AM

Quote:

Originally Posted by dpraveenit (Post 3190956)
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.

tronayne 06-21-2008 10:39 AM

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.


All times are GMT -5. The time now is 10:35 AM.