Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to create a shell script i can run from anywhere in the terminal,

the script simply echoes a message

#!/bin/bash
echo "Excellent work Snake!"

I changed the scripts permissions with

chmod 775 test.sh

the script is in my documents, i made a symbolic link to /usr/bin with

ln -s ./test.sh /usr/bin

when i run the script from home for example, instead of the message echoing, nothing happens, e.g.

babbleshack@babbleshack ~ $ test
babbleshack@babbleshack ~ $ 

am i failing to understand something?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

test is a bash builtin - called with no arguments, as in your example, it does nothing1.

Your shell script is not called test but test.sh, so to run it you need to type:

$ test.sh

However, that's not the only problem. Your command ln -s ./test.sh /usr/bin isn't doing quite what you think - ./test.sh is a relative path, and links to relative paths are relative to the location of the link, not relative to where you were when you typed the command.

You actually want something like:

$ ln -s /home/babbleshack/test.sh /usr/bin

... at which point things ought to work.


1 Technically, it unsuccessfully does nothing (in other words, it returns a non-zero error code). If that means nothing to you, don't worry - it's not important for the purposes of this answer.

share|improve this answer
    
when i run test.sh i get command not found error. I am going to try renaming my script –  Babbleshack Aug 17 '13 at 21:25
    
I renamed my file to foo.sh made a link and i am getting a 'command not found' error –  Babbleshack Aug 17 '13 at 21:30
    
@Babbleshack that probably means your ln -s ./test.sh /usr/bin failed ... do you see an entry for /usr/bin/test.sh if you type ls -l /usr/bin/te*? –  Zero Piraeus Aug 17 '13 at 21:31
    
@Babbleshack are you sure that you successfully made the link? What's in /usr/bin? –  Zero Piraeus Aug 17 '13 at 21:32
    
yer its there i ran ls | grep testme in /usr/bin and it shows the link –  Babbleshack Aug 17 '13 at 21:34
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.