LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2001, 11:52 PM   #1
Daniel
Member
 
Registered: Feb 2001
Location: Oregon
Distribution: Mandrake
Posts: 68

Rep: Reputation: 15
Basic Unix Program for Linux


I am just learning how to program wiht unix, and i came home and tried my program for linux, i make it an executable, but when i type logon Dave to run the program with the name dave it says cannot load program, or maybe it was Logon: No command found. Is there some special command in linux used to execute programs?
Its a program that says "Good morning/afternoon/evening Dave. Today is Fri Jun 22. Local time is 21:33.
 
Old 06-23-2001, 07:45 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
if your program is called 'dave' and it is in the current dir, and it's executable (at least 700) then you should just be able to do
Code:
./dave
and it should run...

Whats with the 'logon' bit?

Jamie...
 
Old 06-23-2001, 11:29 AM   #3
Daniel
Member
 
Registered: Feb 2001
Location: Oregon
Distribution: Mandrake
Posts: 68

Original Poster
Rep: Reputation: 15
Logon is the name of the program, Dave is the input variable. I like choosing dave, because it makes the program say:
Good morning Dave.
Like that computer is the movie 2001.
 
Old 07-03-2001, 05:54 PM   #4
midnightcommander
LQ Newbie
 
Registered: Jan 2001
Location: Parkersburg, WV
Posts: 13

Rep: Reputation: 0
I think it'd be a very good idea, too, to call the program something other than "Logon". The word "Logon" has too specific a meaning to the OS already. Even if there is no other executable in the path with the same name, it's too likely that "Logon" might be used somewhere, someday as a system variable. Another, less common, word might be better.
 
Old 07-04-2001, 04:23 PM   #5
Daniel
Member
 
Registered: Feb 2001
Location: Oregon
Distribution: Mandrake
Posts: 68

Original Poster
Rep: Reputation: 15
It doesnt matter what its called, just a little program i made to help me learn unix shell script... not like im ever going to use it. Anyway, i made my first game on Unix, but when i run it in linux i get an error that says elif is unexpected, and if i change all the elifs to ifs it says unexpected end of file. Is there some other command for elif in linux? Or is somthing else wrong? Here is the source if it helps:

echo "Red Coats"
echo "By Daniel Campbell"
echo ' ______'
echo ' \____/'
echo ' |oo|'
echo ' |/\|'
echo ' \__/'
echo ' _/\/\_'
echo ' / ||//\'
echo ' || |//||'
echo ' || // ||'
echo ' ||//| ||'
sleep 1
men=200
pounds=500
level=1
experience=1
battles=0

while true
do
r1=`date | cut -c18`
r2=`date | cut -c19`
if [ "$pounds" -le 0 ]
then
echo "Your regiment has gone bankrupt!"
exit 1
fi
if [ "$pounds" -ge 2500 ]
then
echo "Thanks to your excellent leadership the campaign has ended in success!"
sleep 2
exit 1
fi
echo "MAIN MENU"
echo "Your regiment is $men strong."
echo "You have $pounds pounds sterling."
echo "What would you like to do?"
echo "\"1\" Attack the enemy."
echo "\"2\" Hire more men."
echo "\"3\" Review encampment."
echo "\"4\" Conduct Training Exercise (40 Sterling)."
echo "\"5\" Exit"
read choice
if [ "$choice" -eq 3 ]
then
echo "REVIEW ENCAMPMENT"
echo "Your men have an experience level of $experience."
echo "The enemy has an experience level of $level."
echo "You have fought $battles battles."
elif [ "$choice" -eq 5 ]
then
echo "Are you sure you want to quit? (y/n)"
read exit
if [ "$exit" != n ]
then
exit 1
fi
elif [ "$choice" -eq 2 ]
then
echo "HIRE MENU"
echo "You have $pounds pounds sterling."
echo "\"1\" Hire 50 men for 100 sterling."
echo "\"2\" Return to main menu."
read hire
if [ "$hire" -eq 2 ]
then
echo
elif [ "$hire" -eq 1 ]
then
pounds=`expr $pounds - 100`
men=`expr $men + 50`
fi
elif [ "$choice" -eq 1 ]
then
echo "CONDUCTING BATTLE"
sleep 1
pre=$men
x1=`expr $experience \* 10`
mn=`expr $x1 + $men`
echo "You attacked with $mn points."
x2=`expr $r2 \* $r1`
x3=`expr $level \* 15`
x4=`expr $x2 \* 10`
enemymen=`expr $x4 + $x3`
echo "The enemy met you with $enemymen points."
if [ "$enemymen" -gt $mn ]
then
echo "You have lost the battle."
pounds=`expr $pounds - 100`
battles=`expr $battles + 1`
else
echo "You have won the battle!"
pounds=`expr $pounds + 100 + $x3`
men=`expr $mn - $enemymen`
level=`expr $level + 1`
experience=`expr $experience + 1`
battles=`expr $battles + 1`
if [ "$men" -gt $pre ]
then
men=$pre
fi
fi
sleep 2
else [ "$choice" -eq 4 ]
echo "CONDUCTING TRAINING EXERCISE"
gain=`expr $r2 / 3`
echo "Your men gain $gain experience from exercise."
experience=`expr $gain + $experience`
pounds=`expr $pounds - 40`
fi
done

Thanks for help..
 
Old 07-04-2001, 08:46 PM   #6
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I had no problems running your script. I used the bash shell.
 
Old 07-05-2001, 12:43 AM   #7
Daniel
Member
 
Registered: Feb 2001
Location: Oregon
Distribution: Mandrake
Posts: 68

Original Poster
Rep: Reputation: 15
What did you think of my program?

How would i get to the bash shell? I jsut click the Terminal Emulation button in the tool bar...

I think the problem might be that I sent it from a .txt file in windows via floppy, and then removed the .txt once in linux. Would that have any effect? If so how can i copy into the shell?
 
Old 07-05-2001, 01:17 AM   #8
cinnix
Member
 
Registered: Jun 2001
Location: Northern Ohio
Distribution: RedHat, Engarde and LFS
Posts: 237

Rep: Reputation: 30
I have had this problem before, open up your file in vi like this..

vim -b FILENAME

(vim -b opens the file as a binary file, if you don't use the -b option you won't be able to see these characters.)

and look for the following character ...

^M

if you see this character anywhere, linux is going to give you a hard time about it. This character is signifying the DOS EOL. You need to go thru this file and remove all of the ^M and any othe ^ character that doesn't belong their. If you edited this file in windows at any time, (cut and paste) you will have this problem.
 
Old 07-05-2001, 08:18 AM   #9
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You can use ftp in asc mode to transfer text files to and from windows. This will remove the ^M for you.

If you do not have a network, you can use the following commands to get rid of the ^M s.

Code:
cat filename.sh | tr '^M' '' > newfilename.sh
To get the ^M to appear in the shell, you must type Control-V then Control-M and you will see the ^M appear. Note that all the quotes are single in the tr comand.

Once you have the file on Linux you can execute it in a bash shell by either:

Typing:
Code:
bash ./filename
Or add this line to the top of your script:

Code:
#!/bin/bash
 
Old 07-05-2001, 08:21 AM   #10
cinnix
Member
 
Registered: Jun 2001
Location: Northern Ohio
Distribution: RedHat, Engarde and LFS
Posts: 237

Rep: Reputation: 30
I must say that was the most useful bit of information I have seen in a long time, I am constantly plagued by that problem. Thank you.
 
Old 07-05-2001, 12:17 PM   #11
Daniel
Member
 
Registered: Feb 2001
Location: Oregon
Distribution: Mandrake
Posts: 68

Original Poster
Rep: Reputation: 15
Ya, thanks guys.
 
  


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
How to program under Linux/Unix platform Igor007 AIX 3 08-20-2004 01:00 PM
How to program under Linux/Unix platform Igor007 Programming 2 08-19-2004 04:54 PM
How to program under Linux/Unix platform Igor007 Linux - Newbie 3 08-19-2004 02:18 PM
How to program under Linux/Unix platform Igor007 Solaris / OpenSolaris 2 08-19-2004 02:17 PM
How to program under Linux/Unix platform Igor007 *BSD 1 08-19-2004 02:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:54 AM.

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
Open Source Consulting | Domain Registration