ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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:
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
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?
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.