Execute a shell script without `./` [duplicate]











up vote
2
down vote

favorite













This question already has an answer here:




  • How to run scripts without typing the full path?

    10 answers




I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript.
Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.



I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.










share|improve this question













marked as duplicate by wjandrea, Sergiy Kolodyazhnyy command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Aug 27 at 22:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
    – wjandrea
    Aug 27 at 21:50








  • 1




    Use the full path or put it in ~/bin
    – Panther
    Aug 27 at 22:22










  • In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
    – Patrick Mevzek
    Aug 31 at 2:00















up vote
2
down vote

favorite













This question already has an answer here:




  • How to run scripts without typing the full path?

    10 answers




I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript.
Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.



I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.










share|improve this question













marked as duplicate by wjandrea, Sergiy Kolodyazhnyy command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Aug 27 at 22:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
    – wjandrea
    Aug 27 at 21:50








  • 1




    Use the full path or put it in ~/bin
    – Panther
    Aug 27 at 22:22










  • In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
    – Patrick Mevzek
    Aug 31 at 2:00













up vote
2
down vote

favorite









up vote
2
down vote

favorite












This question already has an answer here:




  • How to run scripts without typing the full path?

    10 answers




I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript.
Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.



I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.










share|improve this question














This question already has an answer here:




  • How to run scripts without typing the full path?

    10 answers




I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript.
Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.



I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.





This question already has an answer here:




  • How to run scripts without typing the full path?

    10 answers








command-line scripts sh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 27 at 21:46









B.A. Ceradsky

163




163




marked as duplicate by wjandrea, Sergiy Kolodyazhnyy command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Aug 27 at 22:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by wjandrea, Sergiy Kolodyazhnyy command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Aug 27 at 22:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
    – wjandrea
    Aug 27 at 21:50








  • 1




    Use the full path or put it in ~/bin
    – Panther
    Aug 27 at 22:22










  • In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
    – Patrick Mevzek
    Aug 31 at 2:00


















  • FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
    – wjandrea
    Aug 27 at 21:50








  • 1




    Use the full path or put it in ~/bin
    – Panther
    Aug 27 at 22:22










  • In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
    – Patrick Mevzek
    Aug 31 at 2:00
















FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
– wjandrea
Aug 27 at 21:50






FreeBSD and macOS are not Ubuntu. Please ask on unix.stackexchange.com instead.
– wjandrea
Aug 27 at 21:50






1




1




Use the full path or put it in ~/bin
– Panther
Aug 27 at 22:22




Use the full path or put it in ~/bin
– Panther
Aug 27 at 22:22












In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
– Patrick Mevzek
Aug 31 at 2:00




In the past people had . in their PATH which means, at some point, if not found elsewhere, the search will be in current directory. Especially for root or any kind of high power user this is a security nightmare about to happen, so it is best not to have it and force users to input the full path name.
– Patrick Mevzek
Aug 31 at 2:00










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










To run scripts you have written yourself you have a couple options.



OPTION 1



You can store them in /usr/bin.



This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise



I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin



OPTION 2



You can just store them all in your testing folder so in my case...



Documents/SourceCode/



and add this to my path variable.



export PATH=$(PATH):/home/user/Documents/SourceCode






share|improve this answer

















  • 3




    Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
    – Panther
    Aug 27 at 22:24












  • @Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
    – Sergiy Kolodyazhnyy
    Aug 27 at 22:45










  • @Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
    – j-money
    Aug 28 at 3:28










  • With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
    – Panther
    Aug 28 at 3:38










  • Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
    – j-money
    Aug 28 at 3:46


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










To run scripts you have written yourself you have a couple options.



OPTION 1



You can store them in /usr/bin.



This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise



I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin



OPTION 2



You can just store them all in your testing folder so in my case...



Documents/SourceCode/



and add this to my path variable.



export PATH=$(PATH):/home/user/Documents/SourceCode






share|improve this answer

















  • 3




    Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
    – Panther
    Aug 27 at 22:24












  • @Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
    – Sergiy Kolodyazhnyy
    Aug 27 at 22:45










  • @Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
    – j-money
    Aug 28 at 3:28










  • With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
    – Panther
    Aug 28 at 3:38










  • Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
    – j-money
    Aug 28 at 3:46















up vote
1
down vote



accepted










To run scripts you have written yourself you have a couple options.



OPTION 1



You can store them in /usr/bin.



This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise



I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin



OPTION 2



You can just store them all in your testing folder so in my case...



Documents/SourceCode/



and add this to my path variable.



export PATH=$(PATH):/home/user/Documents/SourceCode






share|improve this answer

















  • 3




    Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
    – Panther
    Aug 27 at 22:24












  • @Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
    – Sergiy Kolodyazhnyy
    Aug 27 at 22:45










  • @Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
    – j-money
    Aug 28 at 3:28










  • With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
    – Panther
    Aug 28 at 3:38










  • Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
    – j-money
    Aug 28 at 3:46













up vote
1
down vote



accepted







up vote
1
down vote



accepted






To run scripts you have written yourself you have a couple options.



OPTION 1



You can store them in /usr/bin.



This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise



I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin



OPTION 2



You can just store them all in your testing folder so in my case...



Documents/SourceCode/



and add this to my path variable.



export PATH=$(PATH):/home/user/Documents/SourceCode






share|improve this answer












To run scripts you have written yourself you have a couple options.



OPTION 1



You can store them in /usr/bin.



This is personally what I do as I read somewhere a long time ago that /usr/bin was for things exactly like this and I've never really thought of it otherwise



I do however keep a copy of the scripts in a separate folder Documents/SourceCode/ which is where I do all my editing and testing. then I just copy the script over to /usr/bin



OPTION 2



You can just store them all in your testing folder so in my case...



Documents/SourceCode/



and add this to my path variable.



export PATH=$(PATH):/home/user/Documents/SourceCode







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 27 at 21:54









j-money

355210




355210








  • 3




    Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
    – Panther
    Aug 27 at 22:24












  • @Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
    – Sergiy Kolodyazhnyy
    Aug 27 at 22:45










  • @Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
    – j-money
    Aug 28 at 3:28










  • With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
    – Panther
    Aug 28 at 3:38










  • Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
    – j-money
    Aug 28 at 3:46














  • 3




    Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
    – Panther
    Aug 27 at 22:24












  • @Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
    – Sergiy Kolodyazhnyy
    Aug 27 at 22:45










  • @Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
    – j-money
    Aug 28 at 3:28










  • With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
    – Panther
    Aug 28 at 3:38










  • Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
    – j-money
    Aug 28 at 3:46








3




3




Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
– Panther
Aug 27 at 22:24






Putting the script in ~/bin is better than either of those options. Or if for multiple users /usr/local/bin
– Panther
Aug 27 at 22:24














@Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
– Sergiy Kolodyazhnyy
Aug 27 at 22:45




@Panther Arguably it's the preferred method, but option 2 is same as ~/bin. Difference is that .bashrc on Ubuntu already adds ~/bin to PATH if it exists. I agree with your comment but only partially.
– Sergiy Kolodyazhnyy
Aug 27 at 22:45












@Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
– j-money
Aug 28 at 3:28




@Panther thanks for the catch! I am curious though as to what makes ~/bin "better"?
– j-money
Aug 28 at 3:28












With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
– Panther
Aug 28 at 3:38




With ubuntu, ~/bin is on a users path by default and it does not require root powers so it is very simple
– Panther
Aug 28 at 3:38












Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
– j-money
Aug 28 at 3:46




Ah this would explain, I've never had a multi user system so I've never had to worry about anyone else :'D
– j-money
Aug 28 at 3:46



Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

Eduardo VII do Reino Unido