Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-28-2010, 10:59 PM   #1
LQ Newbie
Registered: Oct 2010
Distribution: Ubuntu
Posts: 10

Rep: Reputation: 0
ksh shell script

I tried to run a ksh shell script, it is very short, but not working.

# writing style: [i]nteractive shellscript
# tested on platform environment: Sun/OS 5.7
# proccess name: vncserver
#start and stop vnc sessions.
printf "Starting VNC servers for: "

case "$1" in
/etc/init.d/vnc $1

echo Stopping vnc sessions
ps -ef|grep -v awk|awk '/Xvnc :/ {print $9}'|while read session
/usr/local/bin/vncserver -kill $session
echo "Usage: $0 [ start | stop ]"
exit 1
exit 0

when I run it, it returns something like...
user@user-desktop:~/Desktop$ ./S99vnc
bash: ./S99vnc: /bin/ksh^M: bad interpreter: No such file or directory

I copied this script online and tried to use it. I even comment out everyline and see what is the major problem, but I still cannot find any problem. Can someone give me a hint? I am using ubuntu vm.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-28-2010, 11:09 PM   #2
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
ksh probably lives in /usr/bin/ksh. You can find out with the command:
which ksh
If it is installed I suspect it will return "/usr/bin/ksh". If that is the case then edit the first line of the script to read
If "which ksh" returns nothing the you probably need to install it:
sudo apt-get install ksh


Last edited by evo2; 10-28-2010 at 11:11 PM.
Old 10-28-2010, 11:10 PM   #3
LQ Guru
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
when I run it, it returns something like...
user@user-desktop:~/Desktop$ ./S99vnc
bash: ./S99vnc: /bin/ksh^M: bad interpreter: No such file or directory
The control-M following your ksh command may be the cause of your problems. It looks like some sort of windows style CF/LF at the end of lines. I see from your user-agent icon that you are using windows so this could well be your problem.
1 members found this post helpful.
Old 10-28-2010, 11:53 PM   #4
LQ Newbie
Registered: Oct 2010
Distribution: Ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
I think my ksh is installed, because I tested with a simple script.
user@user-desktop:~/Desktop/aa$ more ok
#this is a comment!
echo Hello World
user@user-desktop:~/Desktop/aa$ ./ok
Hello World

still very confused!
Old 10-29-2010, 12:12 AM   #5
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Not having ksh installed is not the problem - read jdkaye's post. If you have "fromdos" on your machine, you can fromdos < inscript > outscript, where "inscript" is the original script and "outscript" an output filename, for the script without the ^M characters.
2 members found this post helpful.


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
Ksh Shell conversion rbell54 Linux - Newbie 2 05-18-2009 08:04 AM
Shell Scripting for KSH sagarbsa Programming 1 10-12-2007 05:37 AM
korn shell ( ksh ) lechuga Puppy 3 02-05-2007 09:43 PM
How to change shell to ksh rajeshsfo Linux - Software 3 08-14-2006 02:01 PM
Shell Script that misbehaves under Linux but works in HP UX well... ksh environ. sammathew Linux - Software 7 09-17-2003 08:42 PM

All times are GMT -5. The time now is 02:11 AM.

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