LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-10-2011, 09:54 AM   #1
Rmurphy
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Rep: Reputation: Disabled
unable to execute my file week4prog1Rebecca.scr, what is wrong?


I need help. So far I am not doing as good as I would like in class. I am just not finding the answers I look for to accomplish the right output.
Here is my file. I need to know how to execute this file. Any help will be greatly appreciated.

#!/bin/bash
count=1
echo "start of the program"
while [ $count -le 10 ]
do
echo "Loop #$count"
sleep 10
count=$[ count + 1]

echo "end of the program"
done


Every command that I have found give me an error similar to this one
bash: run: command not found
 
Old 10-10-2011, 10:19 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Try executing your program with
Code:
./week4prog1Rebecca.scr
Of course this assumes that you made the program executable firts?
Code:
chmod 755 week4prog1Rebecca.scr
And, just for the sake of neatness, your program is a shell program; the common practice naming convention is week4prog1Rebecca.sh.

With this naming convention, you can use the make utility to, uh, make your program executable (and without the .sh extension):
Code:
make week4prog1Rebecca
Then execute it with
Code:
./week4prog1Rebecca
make does not remove the extension, rather it "knows" that a .sh source file should be the same file name without the extension (so you just type the name) with its mode changed. Try it and watch what happens.

Hope this helps some.
 
Old 10-10-2011, 10:34 AM   #3
Rmurphy
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
please explain the make command - not understanding

Ok, I have created my file again thanks to my school site that doesn't save anything I have done. I changed the permissions so it would execute but when I do the make command this is the error I am receiving.

make week4prog1Rebecca.scr
make: Nothing to be done for `week4prog1Rebecca.scr'.
[Student@localhost Rebecca]$

do I need to rename the .scr to a .sh?
 
Old 10-10-2011, 10:44 AM   #4
16pide
Member
 
Registered: Jan 2010
Posts: 418

Rep: Reputation: 83
try this:
Code:
mv week4prog1Rebecca.scr week4prog1Rebecca.sh
make week4prog1Rebecca
./week4prog1Rebecca
personally, I would do only this:
Code:
mv week4prog1Rebecca.scr week4prog1Rebecca.sh
chmod u+x week4prog1Rebecca.sh
./week4prog1Rebecca.sh
 
Old 10-10-2011, 10:46 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The make command suggested by tronayne is an alternative way to give executable permissions to the file (but it makes a copy of the original file without extension). Keep it simple and do this:
Code:
chmod +x week4prog1Rebecca.scr
then to run the script do:
Code:
./week4prog1Rebecca.scr
that is you give the relative path of the file. Since it is in the current working directory, you specify the path as ./. If you don't put the path, the system is not able to locate your executable, unless the directory where the script is placed is listed in the PATH environment variable. To actually answer your question: to run a script you have to make it executable and type its absolute or relative path then press enter. That's it.

Quote:
Originally Posted by Rmurphy View Post
do I need to rename the .scr to a .sh?
Nope. Not necessarily. You can rename it .sh for your convenience to easily remind that it is a shell script.

Last edited by colucix; 10-10-2011 at 10:47 AM.
 
Old 10-10-2011, 10:59 AM   #6
Rmurphy
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you, thank you and thank you.

although I found a mistake in my program I think. I did the mv week4prog1Rebecca.scr week4prog1Rebecca.sh
then the chmod +x week4prog1Rebecca.sh (I first change mod was to the .scr file which didn't work)

then ran ./week4prog1Rebecca.scr and that didn't work so I changed it to ./week4prog1Rebecca.sh and it executed the file.....YIPPPIEEEEEE

now here is a twist to the program. I am sorry I keep asking for help but just don't understand all these commands and trying to find help is difficult.

I have to add this:

Modify the program to add a trap for SIGINT and SIGTERM.
save the script and this time run the script in the background, use the jobs command to display a list of the jobs currently running.
find the process id of the script and kill the job (I think I have the commands for this)
check to see if you get the trap message
run the scrip again using the at command to schedule the job in the future. Wait for the job to run to make sure it executes.
 
Old 10-10-2011, 11:34 AM   #7
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
do I need to rename the .scr to a .sh?
Well, yes, you probably do want to do that -- and here's why.

There are naming conventions that are worth your time to follow; e.g.,
  • .sh: shell program source code
  • .c C-language source code
  • .awk AWK program source code
and lots of others.

The key phrase is "source code."

Although many folks will retain the .sh extension on a shell program (and, consequently, will force anyone using that program to type prog.sh), the way Linux is intended to work is that all you need to do is type the name of a program -- no extensions -- and it'll go to work. Source code is kept separate from executable.

Why it's a good idea to do this is really quite simple -- if you write a program (in any of the many languages available to you), chances are that as time goes on you're going to have a larger and larger collection of programs. If you keep your source code separate from the executable, you can easily edit the source without disturbing a program that may be in use by number of folks. That way, you can add features and test your changes without causing any problems until you're ready to "go live" with whatever changes you've made in the source.

What the make utility does is take your source code and turn it into an executable; essentially, as colucix says, make simply copies a shell program source file, eliminating the .sh extension and changes the mode of the copy to make it executable. So, in your case, you would have two files, week4prog1Rebecca.sh (the source) and week4prog1Rebecca (the executable) -- you would simply enter (type) ./week4prog1Rebecca and hit the enter key to run it.

If you were to edit week4prog1Rebecca.sh you would simply
Code:
make week4prog1Rebecca
to re-do the copy-and-change-mode.

Now, make does not simply copy with other languages, notably C and its derivatives, what it does with a C program is compile it to a binary executable; you start with prog.c, execute make prog, and you wind up with an executable prog (see the idea? source to executable with no extension?). For now, don't worry about those details, just bear mind the naming convention and remember that there's a tool, make, that makes it a little easier for you.

As time goes on, you'll become familiar with the make utility -- it's a great tool that makes you life much, much easier and all you have to do is stick with a few conventions to get a great deal of work done with minimal effort (well, less that otherwise would be the case, say).

A couple of other things to keep in mind, particularly if you're coming from a Windows background: no spaces in file names (ever); back slants (\) are not the same thing as slashes (/); it's directory, not folder; file name don't need to be a sentence, but do need to make sense.

Best of luck with all of this.

Hope this helps some.

Last edited by tronayne; 10-10-2011 at 11:36 AM. Reason: Can't spel for beanz
 
Old 10-10-2011, 12:21 PM   #8
Rmurphy
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
I need more help. I am supposed to do the following changes to the file I created earlier and hopefully it will run the way it should.

Here are the requirements - I ask because I am not finding how to make the modifications to my file.

I have to add this:

Modify the program to add a trap for SIGINT and SIGTERM.
save the script and this time run the script in the background, use the jobs command to display a list of the jobs currently running.
find the process id of the script and kill the job (I think I have the commands for this)
check to see if you get the trap message
run the scrip again using the at command to schedule the job in the future. Wait for the job to run to make sure it executes.
 
  


Reply



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
Wine unable to execute .exe file udaya31 Linux - Software 1 04-09-2011 12:41 PM
Unable to change file permissions to execute azm882 Linux - General 2 06-17-2010 09:47 AM
unable to execute a 4GE file in ksh shell gnagendr Programming 7 04-08-2010 01:56 AM
unable to execute gcc: No such file or directory lies Linux - Kernel 10 06-26-2008 01:06 PM
Who can tell me why I am unable to execute bin file under RHEL AS 4? memorinex2005 Red Hat 7 03-10-2005 08:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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