chmod to make executable command

Hey all,

I've done a quick search, but was getting confused with some answers I found, so forgive me if this is answered elsewhere.

I'm trying to install and use the todo.sh shell I found ( https://github.com/ginatrapani/todo.txt-cli/wiki/User-Documentation). I'm struggling to get Terminal to recognize "todo.sh" as an executable command. I type:

sh todo.sh
chmod +x todo.sh

and I get no errors. But then when I type todo.sh it returns

-bash: todo.sh: command not found

I even tried running this in a tcsh, and I get the same result. To be honest, I've never actually been able to get chmod to work for me before, even though I've tried a handful of times.

Does anyone have any ideas?

Thanks

MacBook, Mac OS X (10.6.5)

Posted on Dec 23, 2010 10:33 AM

Reply
4 replies

Dec 23, 2010 11:27 AM in response to khock19

khock19 wrote:
and I get no errors. But then when I type todo.sh it returns

-bash: todo.sh: command not found


You don't have problem with chmod. The problem is that the directory containing that file isn't in your "path". You can see this by typing the command "echo $PATH" (without the quotes). There are three ways to deal with this: (1) Invoke that command this way: ./todo.sh . (That's what the "Quick Start Guide" for that script tells you to do in step 5.) That tells bash to look for that command in the current directory. (2) Presuming you're positioned in the directory where that script file is, add that directory to the path using this command: export PATH=`pwd`:$PATH . You'll have to invoke that command every time you launch a new Terminal session unless you update your bash profile to include a command to set the PATH automatically. (3) Put the file todo.sh in one of the directories that's already in the PATH, such as /usr/local/bin.

Dec 23, 2010 11:32 AM in response to khock19


ls -l todo.sh
-rwxr-xr-x 1 you staff 277 Dec 17 15:21 todo.sh

The x's above indicate if the file has executable permissions. I'm thinking that chmod did add executable permissions, so most like you do not have the directory containing todo.sh in your PATH environment variable.

You can continue to use the "sh todo.sh" approach, or you can specify a path to the todo.sh

./todo.sh # assumes you are in the directory with todo.sh
# -OR-
$HOME/todo.sh # assumes todo.sh is in your home directory
# -OR-
/full/path/to/todo.sh

You could also modify the PATH environment variable and put the directory with todo.sh in your PATH.

You modify PATH in your .bash_profile (does not exist if you have not created one in the past), or the .profile (bash will choose .bash_profile over .profile, and .profile does not exist unless you created it in the past).

Modifying PATH would be done something like:

nano .bash_profile

and add

export PATH="$PATH:/full/path/to/the/directory"

ONLY You know what /full/path/to/the/directory containing todo.sh is.

Dec 23, 2010 12:26 PM in response to khock19

Others have provided you with the correct answer.

I'll leave you with the following example...


$ ./x.sh
-bash: ./x.sh: Permission denied
$ chmod +x x.sh
$ ./x.sh
Hi
$ ./y.sh
-bash: ./y.sh: No such file or directory
$ ls y.sh
ls: y.sh: No such file or directory
$ y.sh
-bash: y.sh: command not found
$ cat x.sh
echo "Hi"
$


Note the different diagnostics.

Dec 23, 2010 12:31 PM in response to BobHarris

Excellent, thank you very much.

I modified my .bash_profile to automatically update the Path every time Terminal starts. I suppose I could have moved the .sh file, but I wanted experience telling it where to look. I guess I just assumed chmod would update the path to know where an executable was located, but Unix only does what you tell it to I suppose.

Thanks everyone

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

chmod to make executable command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.