Does using ./ in paths make sense with common Unix tools?2019 Community Moderator ElectionWhy cat, grep and other commands can't understand files starting with minus sign?What does the ./ mean (dot slash) in linux?History of UNIX not including current directory in $PATHAdding paths to PATH using a multi-line syntaxMake problem with includesbroken pipe error with popen and JS ffiWhy isn't there any shell command to create files?Is it possible to drop all write privileges in a shell for the current userBash pattern to match directories whose names begin with a dot (period), by being “explicit”, instead of using “shopt -s dotglob”?How to fetch one file from two paths in unix?How to make sense of non-interactive login shell?Should we use UTF-8 characters like ⏰ in bash/shell script?Using unusual paths with commands
Freedom of speech and where it applies
Bob has never been a M before
Is there a problem with hiding "forgot password" until it's needed?
Is there enough fresh water in the world to eradicate the drinking water crisis?
Invariance of results when scaling explanatory variables in logistic regression, is there a proof?
Adding empty element to declared container without declaring type of element
Why does this part of the Space Shuttle launch pad seem to be floating in air?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How to deal with or prevent idle in the test team?
Are Warlocks Arcane or Divine?
Perfect riffle shuffles
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
Is infinity mathematically observable?
Can the harmonic series explain the origin of the major scale?
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
Can I Retrieve Email Addresses from BCC?
Did US corporations pay demonstrators in the German demonstrations against article 13?
Partial sums of primes
Can a Bard use an arcane focus?
Have I saved too much for retirement so far?
Can I rely on these GitHub repository files?
Is there an wasy way to program in Tikz something like the one in the image?
How to interpret the phrase "t’en a fait voir à toi"?
Visiting the UK as unmarried couple
Does using ./ in paths make sense with common Unix tools?
2019 Community Moderator ElectionWhy cat, grep and other commands can't understand files starting with minus sign?What does the ./ mean (dot slash) in linux?History of UNIX not including current directory in $PATHAdding paths to PATH using a multi-line syntaxMake problem with includesbroken pipe error with popen and JS ffiWhy isn't there any shell command to create files?Is it possible to drop all write privileges in a shell for the current userBash pattern to match directories whose names begin with a dot (period), by being “explicit”, instead of using “shopt -s dotglob”?How to fetch one file from two paths in unix?How to make sense of non-interactive login shell?Should we use UTF-8 characters like ⏰ in bash/shell script?Using unusual paths with commands
Throughout the years I've been using ./
in front of absolute paths more and more.
For example:
mv ./file /target/
rm ./something/else
# compared to
mv file /target/
rm something/else
I've seen it in more places around the web, which is probably why I adapted to using it. I can't seem to understand why this is done though, and have been wondering for a while.
Maybe it's a bad habit originating from calling local binaries directly: ./a.out
Is the ./
obsolete in the shell example above? Is there any reason to use ./
in some cases? Does using it possibly make paths more explicit?
shell path
add a comment |
Throughout the years I've been using ./
in front of absolute paths more and more.
For example:
mv ./file /target/
rm ./something/else
# compared to
mv file /target/
rm something/else
I've seen it in more places around the web, which is probably why I adapted to using it. I can't seem to understand why this is done though, and have been wondering for a while.
Maybe it's a bad habit originating from calling local binaries directly: ./a.out
Is the ./
obsolete in the shell example above? Is there any reason to use ./
in some cases? Does using it possibly make paths more explicit?
shell path
1
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
1
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday
add a comment |
Throughout the years I've been using ./
in front of absolute paths more and more.
For example:
mv ./file /target/
rm ./something/else
# compared to
mv file /target/
rm something/else
I've seen it in more places around the web, which is probably why I adapted to using it. I can't seem to understand why this is done though, and have been wondering for a while.
Maybe it's a bad habit originating from calling local binaries directly: ./a.out
Is the ./
obsolete in the shell example above? Is there any reason to use ./
in some cases? Does using it possibly make paths more explicit?
shell path
Throughout the years I've been using ./
in front of absolute paths more and more.
For example:
mv ./file /target/
rm ./something/else
# compared to
mv file /target/
rm something/else
I've seen it in more places around the web, which is probably why I adapted to using it. I can't seem to understand why this is done though, and have been wondering for a while.
Maybe it's a bad habit originating from calling local binaries directly: ./a.out
Is the ./
obsolete in the shell example above? Is there any reason to use ./
in some cases? Does using it possibly make paths more explicit?
shell path
shell path
edited yesterday
Tim Visee
asked yesterday
Tim ViseeTim Visee
1086
1086
1
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
1
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday
add a comment |
1
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
1
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday
1
1
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
1
1
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday
add a comment |
1 Answer
1
active
oldest
votes
It's not a bad habit to specify explicitly that something is located in the current directory, especially when that something is a script or program (the alternative in that case would be to have .
in your $PATH
which is generally considered to be a security risk).
There are situations where you will have ./
at the start of a pathname no matter if you want it or not. For example, the pathnames found by find
when searching from .
downwards will always be prefixed by ./
.
In other situations, a filename may interfere with the options of a utility, as when trying to remove a file called -f
with
rm -f
Using
rm ./-f
would solve that (the ./-f
would not be taken as an option to rm
), as would
rm -- -f
do (the --
signals the end of any command line options).
Also note that shell globs, such as *
may expand to files with an initial dash. It is therefore safer to e.g. loop over ./*
than over *
(unless you use --
to delimit the unknown filename from the options given to utilities).
It is therefore a good idea to use ./
in pathnames, particularly if the pathname is stored in a variable and comes from some source external to the script.
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f508336%2fdoes-using-in-paths-make-sense-with-common-unix-tools%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
It's not a bad habit to specify explicitly that something is located in the current directory, especially when that something is a script or program (the alternative in that case would be to have .
in your $PATH
which is generally considered to be a security risk).
There are situations where you will have ./
at the start of a pathname no matter if you want it or not. For example, the pathnames found by find
when searching from .
downwards will always be prefixed by ./
.
In other situations, a filename may interfere with the options of a utility, as when trying to remove a file called -f
with
rm -f
Using
rm ./-f
would solve that (the ./-f
would not be taken as an option to rm
), as would
rm -- -f
do (the --
signals the end of any command line options).
Also note that shell globs, such as *
may expand to files with an initial dash. It is therefore safer to e.g. loop over ./*
than over *
(unless you use --
to delimit the unknown filename from the options given to utilities).
It is therefore a good idea to use ./
in pathnames, particularly if the pathname is stored in a variable and comes from some source external to the script.
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
add a comment |
It's not a bad habit to specify explicitly that something is located in the current directory, especially when that something is a script or program (the alternative in that case would be to have .
in your $PATH
which is generally considered to be a security risk).
There are situations where you will have ./
at the start of a pathname no matter if you want it or not. For example, the pathnames found by find
when searching from .
downwards will always be prefixed by ./
.
In other situations, a filename may interfere with the options of a utility, as when trying to remove a file called -f
with
rm -f
Using
rm ./-f
would solve that (the ./-f
would not be taken as an option to rm
), as would
rm -- -f
do (the --
signals the end of any command line options).
Also note that shell globs, such as *
may expand to files with an initial dash. It is therefore safer to e.g. loop over ./*
than over *
(unless you use --
to delimit the unknown filename from the options given to utilities).
It is therefore a good idea to use ./
in pathnames, particularly if the pathname is stored in a variable and comes from some source external to the script.
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
add a comment |
It's not a bad habit to specify explicitly that something is located in the current directory, especially when that something is a script or program (the alternative in that case would be to have .
in your $PATH
which is generally considered to be a security risk).
There are situations where you will have ./
at the start of a pathname no matter if you want it or not. For example, the pathnames found by find
when searching from .
downwards will always be prefixed by ./
.
In other situations, a filename may interfere with the options of a utility, as when trying to remove a file called -f
with
rm -f
Using
rm ./-f
would solve that (the ./-f
would not be taken as an option to rm
), as would
rm -- -f
do (the --
signals the end of any command line options).
Also note that shell globs, such as *
may expand to files with an initial dash. It is therefore safer to e.g. loop over ./*
than over *
(unless you use --
to delimit the unknown filename from the options given to utilities).
It is therefore a good idea to use ./
in pathnames, particularly if the pathname is stored in a variable and comes from some source external to the script.
It's not a bad habit to specify explicitly that something is located in the current directory, especially when that something is a script or program (the alternative in that case would be to have .
in your $PATH
which is generally considered to be a security risk).
There are situations where you will have ./
at the start of a pathname no matter if you want it or not. For example, the pathnames found by find
when searching from .
downwards will always be prefixed by ./
.
In other situations, a filename may interfere with the options of a utility, as when trying to remove a file called -f
with
rm -f
Using
rm ./-f
would solve that (the ./-f
would not be taken as an option to rm
), as would
rm -- -f
do (the --
signals the end of any command line options).
Also note that shell globs, such as *
may expand to files with an initial dash. It is therefore safer to e.g. loop over ./*
than over *
(unless you use --
to delimit the unknown filename from the options given to utilities).
It is therefore a good idea to use ./
in pathnames, particularly if the pathname is stored in a variable and comes from some source external to the script.
edited yesterday
answered yesterday
KusalanandaKusalananda
137k17258426
137k17258426
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
add a comment |
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
So that aggregates into it being obsolete, with the exception for some arguably uncommon situations. Thanks!
– Tim Visee
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
@TimVisee If you ever do any amount of shell scripting for other people than yourself, you will run into these "uncommon" situations every once in a while, if not often.
– Kusalananda
yesterday
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f508336%2fdoes-using-in-paths-make-sense-with-common-unix-tools%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
1
Here's one reason: Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
yesterday
1
Also unix.stackexchange.com/q/397524/117549
– Jeff Schaller
yesterday