PDA

View Full Version : Bash script - can't open *.sh



coombesy
June 1st, 2008, 12:25 PM
Hi,

trying to write a bash script to clean up my desktop. Learning bash scripting passed two days, so solution might be obvious.

del_Torrents.sh

#!/bin/bash

rm -r ./*.torrent

(gonna start of simple) My 1st problem is that when i run:

coombes@coombes-laptop:~/Desktop$sudo sh del_Torrents.sh

i get:

sh: Can't open del_Torrents.sh

I did get this to work yesterday, after a few attempts. But today it's not! any ideas would be helpful.
Cheers.

ifross
June 1st, 2008, 12:34 PM
Have you made the script excecutable?


chmod a+x del_torrents.sh

geirha
June 1st, 2008, 01:29 PM
sh: Can't open del_Torrents.sh

That error message means it can't find the file. Are you sure the file is still there, and you typed the name correct? (remember, linux is case sensitive)

Majorix
June 1st, 2008, 01:34 PM
Why don't you just use the terminal for this?

dje
June 1st, 2008, 01:37 PM
Try this (make sure you are in the correct directory where the script is):

sudo ./del_Torrents.sh
You need the './' in front of the script because it isn't in the PATH variable

hope that helps,
dje

Prospero2006
June 1st, 2008, 01:55 PM
You Could:

Chmod the script as mentioned above.
Copy it to /usr/local/bin/
Type del_tor(tab)

or

Create an Alias

stroyan
June 1st, 2008, 01:56 PM
Have you made the script excecutable?


chmod a+x del_torrents.sh

If started with "sudo sh del_Torrents.sh" the file does not actually
need to be executable


You need the './' in front of the script because it isn't in the PATH variable


If started with "sh del_Torrents.sh" the file does not actually need to
be executable. It only needs to be readable. It also does not need to
be in a directory in $PATH, as long at it is in the current directory.
Both of those requirements do apply for running a script by name without
any explicit sh or bash command.

I favor the case-sensitive typo theory, or being in a different directory
than the del_Torrents.sh file. The same error message could come from a
permissions problem if the file is present but not readable. But running
sh with sudo will make any existing file readable to that sh.