Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie confusion: script error

Status
Not open for further replies.

chals1

Technical User
Sep 3, 2003
73
ES
Wherever i try running any script linux shouts
: bad interpreter: No such file or directory

I've read i must put scripts in a directory in my PATH. I may put them in /usr/bin or /usr/local/bin and make them executable?

That's a problem.I've no access to these directories
Can i make scripts run anywhere with execute permission?
 
I've read i must put scripts in a directory in my PATH
Where did you read this?
(and it's a Linux-client question, isn't it?)
If you wrote it for sh, you can start it by:
Code:
sh myscript.sh
or
Code:
chmod u+x myscript.sh
./myscript.sh
make a ~/bin dir and move often used scripts there, and add ~/bin to your path. Then you find them from anywhere.

seeking a job as java-programmer in Berlin:
 
now i get
bash: scr:command not found
 
It's totally up to you where you place scripts. There is no real "must" to place them in special directories. It differs where to place them, relating for what job they are doing.
Usually /usr/local/bin or /usr/local/sbin might be a good place. You have to have those dirs in your PATH only, if you don't want to execute them, typing relative or absolute paths in front of the script's name itself.

Can we see the code of the script maybe? Seems you're trying to use some command "scr" in your script that your machine does not know (never seen this command before either). Is it another self made script?

laters
zaxxon
 
Did you write these scipts on a windows box, them ftp'd them over?
Does the script look OK if you do a 'cat -v scriptname' ?
 
If you wrote the scripts in Windows, you will have to remove the ^M characters. This causes confusion in the script. Also make sure there is no space left on the end of each line.

 
Since you've used DOS and Windows, the path thing shouldn't be too hard. The main difference is that, under Linux, the current directory isn't normally searched as part of the PATH.

Put your scripts whever you like. If they're in the path, then they'll run when you type the name. If not, then just type the whole path. Same as DOS.

Also, the extension doesn't mean anything except to you. When a script has the "x" attribute set, it is executable. Even if it doesn't, you can run it by typing "sh script" as mentioned before. If you just want it to run by typing "script", then type "chmod +x script". That'll make it executable for everyone. Also, the first line in this case should be something like "#!/bin/sh" so the OS knows what interpreter to use. Loosely speaking, that's what Linux uses instead of an extension to know how to run it.

And follow comtec17's instructions regarding the extra ^M's.

 
I am quite sure that when trying to read the #!/bin/sh line its encountering the ^M therefore saying ": bad interpreter: No such file or directory".
chals1 thats why I asked if you wrote them on a windows box.
Try to run the dos2unix utility before ftp'ing it over (from here for example: Otherwise you will need to edit the script on your linux box.
From a command line in linux use the command "cat -v /path/to/your/script", do you see the extra characters?
 
I wrote these scipts on windows TextPad but saved as unix format.Anyway i checked in joe and they are right.

I've the two scripts in the same directory than torrent files
I cannot put them in /usr/bin or /usr/local/bin

To run the scripts i type the whole path.Same as DOS.
Then i type sh scr.sh and get this error:

job screen id
ls: /home/alma/ .screen: doesn't exist file or directory

scripts are in /home/cris/...go on.....

When i type
sh bt.sh blabla.torrent
it says cannot execute
 
Try the whole path:
Code:
/homee/chris/foo/bt.sh /homee/chris/foo/blabla.torrent
Or move first to the dir
Code:
cd /homee/chris/foo
bt.sh blabla.torrent

avoid blanks in paths or you end up typing:
Code:
cd /homee/chris/...go\ on...
#or
cd "/homee/chris/...go on..."


seeking a job as java-programmer in Berlin:
 
I had a similar problem myself. easiest way to sort this out is to use vi as so:
Code:
 vi Somescript.sh
:set ff=unix
ZZ

That will sort them out.

Cheers
Xaq

---

"I'm just here to regulate funkyness"
 
Sorry, forgot to mention. How to test for the Windows/Linux LF problem in a script:
Code:
 [root@testmachine /tmp]# ./somescript.sh
     bash: ./somescript.sh: bad interpreter: No such file or directory
     [root@testmachine /tmp]# sh somescript.sh
     : command not found
     : command not found
     somescript.sh: line 45: syntax error near unexpected token 'fi'
     [root@testmachine /tmp]# file somescript.sh
     somescript.sh: Bourne shell script text executable
     [root@testmachine /tmp]#

If your error messages look similar, then CF LF/CF problems are probably the cause. BTW, you don't have to be root to do this, just someone who can access the file....

Cheers
Xaq

---

"I'm just here to regulate funkyness"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top