Having trouble getting my bash script to be executable
My script, learn-fork.sh
, is the following, plus a lot of comments (which will be un-commented once I get the test lines to work)
#!/bin/bash
echo "Running from ${0}"
In addition to that file, I have another file that shows in Finder as learn-fork
(no extension) but that shows up in the terminal as learn-fork.sh-e
Here are the permissions on those files.
-rwxr-xr-x 1 TuzsNewMacBook admin 250 Jan 1 18:25 learn-fork.sh
-rwxr-xr-x@ 1 TuzsNewMacBook admin 307 Jan 1 13:38 learn-fork.sh-e
Running learn-fork.sh
works.
Running learn-fork
gives -bash: learn-fork: command not found
.
bash
|
show 6 more comments
My script, learn-fork.sh
, is the following, plus a lot of comments (which will be un-commented once I get the test lines to work)
#!/bin/bash
echo "Running from ${0}"
In addition to that file, I have another file that shows in Finder as learn-fork
(no extension) but that shows up in the terminal as learn-fork.sh-e
Here are the permissions on those files.
-rwxr-xr-x 1 TuzsNewMacBook admin 250 Jan 1 18:25 learn-fork.sh
-rwxr-xr-x@ 1 TuzsNewMacBook admin 307 Jan 1 13:38 learn-fork.sh-e
Running learn-fork.sh
works.
Running learn-fork
gives -bash: learn-fork: command not found
.
bash
3
Re: "It's in/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running$PATH
as a command, and Bash is complaining that it can't find a program at/Applications/Postgres.app/.../.rvm/bin
. If you just want to print$PATH
, you should writeecho "$PATH"
orprintf '%sn' "$PATH"
.
– ruakh
Jan 1 at 19:08
4
If you want to invoke it under the namelearn-fork
, don't name itlearn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.
– Charles Duffy
Jan 1 at 19:11
2
If you still had a system where it did work, you could runtype learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have acommand_not_found_handle
function that tries looking forfoo.sh
whenfoo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, andtype
doesn't find it, usingset -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).
– Charles Duffy
Jan 1 at 19:21
2
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
2
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.
– Dan Farrell
Jan 1 at 19:53
|
show 6 more comments
My script, learn-fork.sh
, is the following, plus a lot of comments (which will be un-commented once I get the test lines to work)
#!/bin/bash
echo "Running from ${0}"
In addition to that file, I have another file that shows in Finder as learn-fork
(no extension) but that shows up in the terminal as learn-fork.sh-e
Here are the permissions on those files.
-rwxr-xr-x 1 TuzsNewMacBook admin 250 Jan 1 18:25 learn-fork.sh
-rwxr-xr-x@ 1 TuzsNewMacBook admin 307 Jan 1 13:38 learn-fork.sh-e
Running learn-fork.sh
works.
Running learn-fork
gives -bash: learn-fork: command not found
.
bash
My script, learn-fork.sh
, is the following, plus a lot of comments (which will be un-commented once I get the test lines to work)
#!/bin/bash
echo "Running from ${0}"
In addition to that file, I have another file that shows in Finder as learn-fork
(no extension) but that shows up in the terminal as learn-fork.sh-e
Here are the permissions on those files.
-rwxr-xr-x 1 TuzsNewMacBook admin 250 Jan 1 18:25 learn-fork.sh
-rwxr-xr-x@ 1 TuzsNewMacBook admin 307 Jan 1 13:38 learn-fork.sh-e
Running learn-fork.sh
works.
Running learn-fork
gives -bash: learn-fork: command not found
.
bash
bash
edited Jan 2 at 9:03


E_net4
12.5k73772
12.5k73772
asked Jan 1 at 19:05


Jonathan TuzmanJonathan Tuzman
495517
495517
3
Re: "It's in/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running$PATH
as a command, and Bash is complaining that it can't find a program at/Applications/Postgres.app/.../.rvm/bin
. If you just want to print$PATH
, you should writeecho "$PATH"
orprintf '%sn' "$PATH"
.
– ruakh
Jan 1 at 19:08
4
If you want to invoke it under the namelearn-fork
, don't name itlearn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.
– Charles Duffy
Jan 1 at 19:11
2
If you still had a system where it did work, you could runtype learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have acommand_not_found_handle
function that tries looking forfoo.sh
whenfoo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, andtype
doesn't find it, usingset -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).
– Charles Duffy
Jan 1 at 19:21
2
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
2
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.
– Dan Farrell
Jan 1 at 19:53
|
show 6 more comments
3
Re: "It's in/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running$PATH
as a command, and Bash is complaining that it can't find a program at/Applications/Postgres.app/.../.rvm/bin
. If you just want to print$PATH
, you should writeecho "$PATH"
orprintf '%sn' "$PATH"
.
– ruakh
Jan 1 at 19:08
4
If you want to invoke it under the namelearn-fork
, don't name itlearn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.
– Charles Duffy
Jan 1 at 19:11
2
If you still had a system where it did work, you could runtype learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have acommand_not_found_handle
function that tries looking forfoo.sh
whenfoo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, andtype
doesn't find it, usingset -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).
– Charles Duffy
Jan 1 at 19:21
2
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
2
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.
– Dan Farrell
Jan 1 at 19:53
3
3
Re: "It's in
/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running $PATH
as a command, and Bash is complaining that it can't find a program at /Applications/Postgres.app/.../.rvm/bin
. If you just want to print $PATH
, you should write echo "$PATH"
or printf '%sn' "$PATH"
.– ruakh
Jan 1 at 19:08
Re: "It's in
/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running $PATH
as a command, and Bash is complaining that it can't find a program at /Applications/Postgres.app/.../.rvm/bin
. If you just want to print $PATH
, you should write echo "$PATH"
or printf '%sn' "$PATH"
.– ruakh
Jan 1 at 19:08
4
4
If you want to invoke it under the name
learn-fork
, don't name it learn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.– Charles Duffy
Jan 1 at 19:11
If you want to invoke it under the name
learn-fork
, don't name it learn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.– Charles Duffy
Jan 1 at 19:11
2
2
If you still had a system where it did work, you could run
type learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have a command_not_found_handle
function that tries looking for foo.sh
when foo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, and type
doesn't find it, using set -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).– Charles Duffy
Jan 1 at 19:21
If you still had a system where it did work, you could run
type learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have a command_not_found_handle
function that tries looking for foo.sh
when foo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, and type
doesn't find it, using set -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).– Charles Duffy
Jan 1 at 19:21
2
2
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
2
2
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.
ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.– Dan Farrell
Jan 1 at 19:53
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.
ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.– Dan Farrell
Jan 1 at 19:53
|
show 6 more comments
1 Answer
1
active
oldest
votes
If you want to invoke it with the command learn-fork
, name the file learn-fork
.
Exactly that, no extension whatsoever. Not learn-fork.sh
, or learn-fork.sh-e
, or anything else -- just learn-fork
.
Treating a file extension as something separate that's not really part of a name is a Windows-ism; UNIX-y folks (and UNIX-y operating systems) don't believe in it. Thus, if you want a command named foo
, the executable or script associated must be named foo
, not foo.anything
.
And it must be marked as executable with chmod +x foo
AND called with a correct path reference, either ./foo
or /path/to/foo
OR where /path/to
is included in the PATH variable, i.e. export PATH="/path/to:$PATH"
.
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998169%2fhaving-trouble-getting-my-bash-script-to-be-executable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to invoke it with the command learn-fork
, name the file learn-fork
.
Exactly that, no extension whatsoever. Not learn-fork.sh
, or learn-fork.sh-e
, or anything else -- just learn-fork
.
Treating a file extension as something separate that's not really part of a name is a Windows-ism; UNIX-y folks (and UNIX-y operating systems) don't believe in it. Thus, if you want a command named foo
, the executable or script associated must be named foo
, not foo.anything
.
And it must be marked as executable with chmod +x foo
AND called with a correct path reference, either ./foo
or /path/to/foo
OR where /path/to
is included in the PATH variable, i.e. export PATH="/path/to:$PATH"
.
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
add a comment |
If you want to invoke it with the command learn-fork
, name the file learn-fork
.
Exactly that, no extension whatsoever. Not learn-fork.sh
, or learn-fork.sh-e
, or anything else -- just learn-fork
.
Treating a file extension as something separate that's not really part of a name is a Windows-ism; UNIX-y folks (and UNIX-y operating systems) don't believe in it. Thus, if you want a command named foo
, the executable or script associated must be named foo
, not foo.anything
.
And it must be marked as executable with chmod +x foo
AND called with a correct path reference, either ./foo
or /path/to/foo
OR where /path/to
is included in the PATH variable, i.e. export PATH="/path/to:$PATH"
.
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
add a comment |
If you want to invoke it with the command learn-fork
, name the file learn-fork
.
Exactly that, no extension whatsoever. Not learn-fork.sh
, or learn-fork.sh-e
, or anything else -- just learn-fork
.
Treating a file extension as something separate that's not really part of a name is a Windows-ism; UNIX-y folks (and UNIX-y operating systems) don't believe in it. Thus, if you want a command named foo
, the executable or script associated must be named foo
, not foo.anything
.
And it must be marked as executable with chmod +x foo
AND called with a correct path reference, either ./foo
or /path/to/foo
OR where /path/to
is included in the PATH variable, i.e. export PATH="/path/to:$PATH"
.
If you want to invoke it with the command learn-fork
, name the file learn-fork
.
Exactly that, no extension whatsoever. Not learn-fork.sh
, or learn-fork.sh-e
, or anything else -- just learn-fork
.
Treating a file extension as something separate that's not really part of a name is a Windows-ism; UNIX-y folks (and UNIX-y operating systems) don't believe in it. Thus, if you want a command named foo
, the executable or script associated must be named foo
, not foo.anything
.
And it must be marked as executable with chmod +x foo
AND called with a correct path reference, either ./foo
or /path/to/foo
OR where /path/to
is included in the PATH variable, i.e. export PATH="/path/to:$PATH"
.
edited Jan 2 at 4:08
community wiki
2 revs, 2 users 80%
Charles Duffy
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
add a comment |
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
I went into finder and deleted the extension. Where that extension came from, who knows. Thanks!
– Jonathan Tuzman
Jan 2 at 5:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998169%2fhaving-trouble-getting-my-bash-script-to-be-executable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Re: "It's in
/usr/local/bin
which is in my PATH (though I'm curious about what looks like an error at the end)": That entire line is an error-message. You're running$PATH
as a command, and Bash is complaining that it can't find a program at/Applications/Postgres.app/.../.rvm/bin
. If you just want to print$PATH
, you should writeecho "$PATH"
orprintf '%sn' "$PATH"
.– ruakh
Jan 1 at 19:08
4
If you want to invoke it under the name
learn-fork
, don't name itlearn-fork.sh
. Extensions should be used for shell libraries, not for scripts. Pretty much everything I have to say on the subject can also be found at Commandname extensions considered harmful.– Charles Duffy
Jan 1 at 19:11
2
If you still had a system where it did work, you could run
type learn-fork
to find out why -- if there's an alias or shell function intercepting the name. Suppose it's also conceivable your system could have acommand_not_found_handle
function that tries looking forfoo.sh
whenfoo
doesn't exist, but that's an awfully janky kind of hack to rely on. (If so, andtype
doesn't find it, usingset -x
to enable logging should expose that... but again, you'd need a system where the extensionless name worked).– Charles Duffy
Jan 1 at 19:21
2
It's best to think of file extension as just part of file name. There's nothing magical about extension in unix; a .txt extension that was in your path and executable works run just as well as .sh, .exe, or like Charles Duffy recommends with no extension at all. The specified file name does need to be accurate - the extension can't be omitted because it's part of the file.
– Dan Farrell
Jan 1 at 19:50
2
"I've tried chmod +x learn-fork.sh, a thousand times" this isn't magic, just file attributes.
ls -l
will show whether executable bit is set. Blindly and repetitively executing commands can only further confuse things.– Dan Farrell
Jan 1 at 19:53