LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-28-2010, 11:59 PM   #1
SharonGe
LQ Newbie
 
Registered: Oct 2010
Distribution: Ubuntu
Posts: 10

Rep: Reputation: 0
ksh shell script


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

#!/bin/ksh
# 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
'start')
/etc/init.d/vnc $1
;;

'stop')
echo Stopping vnc sessions
ps -ef|grep -v awk|awk '/Xvnc :/ {print $9}'|while read session
do
/usr/local/bin/vncserver -kill $session
done
;;
*)
echo "Usage: $0 [ start | stop ]"
exit 1
;;
esac
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-29-2010, 12:09 AM   #2
evo2
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:
Code:
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
Code:
#!/usr/bin/ksh
If "which ksh" returns nothing the you probably need to install it:
Code:
sudo apt-get install ksh
Cheers,

Evo2.

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

Rep: Reputation: Disabled
Quote:
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.
ciao,
jdk
 
1 members found this post helpful.
Old 10-29-2010, 12:53 AM   #4
SharonGe
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
#!/bin/ksh
#this is a comment!
echo Hello World
user@user-desktop:~/Desktop/aa$
user@user-desktop:~/Desktop/aa$ ./ok
Hello World


still very confused!
 
Old 10-29-2010, 01:12 AM   #5
Nylex
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.
  


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


All times are GMT -5. The time now is 10:27 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