What's Linux test -a command test for?
Please take a look at the following code,
snap=snapshot.file
touch snapshot.file-1
$ [ -a $snap-1 ] && echo yes
yes
What does the test -a
command tests for here?
I tried info coreutils 'test invocation'
and searched for -a
, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.
Is such test -a
command an undocumented one?
NB, My system is Ubuntu 13.10 and my man test
says GNU coreutils 8.20 October 2012 TEST(1).
linux ubuntu command-line command-line-arguments
add a comment |
Please take a look at the following code,
snap=snapshot.file
touch snapshot.file-1
$ [ -a $snap-1 ] && echo yes
yes
What does the test -a
command tests for here?
I tried info coreutils 'test invocation'
and searched for -a
, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.
Is such test -a
command an undocumented one?
NB, My system is Ubuntu 13.10 and my man test
says GNU coreutils 8.20 October 2012 TEST(1).
linux ubuntu command-line command-line-arguments
add a comment |
Please take a look at the following code,
snap=snapshot.file
touch snapshot.file-1
$ [ -a $snap-1 ] && echo yes
yes
What does the test -a
command tests for here?
I tried info coreutils 'test invocation'
and searched for -a
, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.
Is such test -a
command an undocumented one?
NB, My system is Ubuntu 13.10 and my man test
says GNU coreutils 8.20 October 2012 TEST(1).
linux ubuntu command-line command-line-arguments
Please take a look at the following code,
snap=snapshot.file
touch snapshot.file-1
$ [ -a $snap-1 ] && echo yes
yes
What does the test -a
command tests for here?
I tried info coreutils 'test invocation'
and searched for -a
, but didn't find it in the file characteristic tests section, but rather in the connectives for test section.
Is such test -a
command an undocumented one?
NB, My system is Ubuntu 13.10 and my man test
says GNU coreutils 8.20 October 2012 TEST(1).
linux ubuntu command-line command-line-arguments
linux ubuntu command-line command-line-arguments
edited Feb 21 at 16:53
xpt
asked Jun 17 '14 at 1:33
xptxpt
3,216145693
3,216145693
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I am not sure why the info
page doesn't have it, but running help test
in bash
gives the answer:
...
File operators:
-a FILE True if file exists.
...
So it is simply an "existence" test, no other permissions/attributes checked.
Perfect! Thanks. Strange,man test
doesn't have that either. onlyhelp test
does. Does that mean it is abash
specific file existence testing?
– xpt
Jun 17 '14 at 3:57
1
@xpt It would seem like that is the case, but for me/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.
– BenjiWiebe
Jun 17 '14 at 12:13
add a comment |
If you're running test
or [
in bash
, it's actually probably the built-in version, and not the coreutils
version in /usr/bin
:
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
That said, it does appear that the coreutils version implements both -a
and -e
, with exactly the same behavior. Maybe -a
is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a
is supposed to be short for).
add a comment |
-a
is the AND operator for combining conditions, so the following shows yes if both directories exist:
[ -e /root -a -e /usr ] && echo yes
The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.
Reference (scroll down some after info coreutils 'test invocation'
):
16.3.6 Connectives for `test'
The usual logical connectives.
`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'
True if either EXPR1 or EXPR2 is true.
1
If you look at the coreutils source, thea
ande
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.
– jjlin
Jun 17 '14 at 17:33
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f769670%2fwhats-linux-test-a-command-test-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am not sure why the info
page doesn't have it, but running help test
in bash
gives the answer:
...
File operators:
-a FILE True if file exists.
...
So it is simply an "existence" test, no other permissions/attributes checked.
Perfect! Thanks. Strange,man test
doesn't have that either. onlyhelp test
does. Does that mean it is abash
specific file existence testing?
– xpt
Jun 17 '14 at 3:57
1
@xpt It would seem like that is the case, but for me/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.
– BenjiWiebe
Jun 17 '14 at 12:13
add a comment |
I am not sure why the info
page doesn't have it, but running help test
in bash
gives the answer:
...
File operators:
-a FILE True if file exists.
...
So it is simply an "existence" test, no other permissions/attributes checked.
Perfect! Thanks. Strange,man test
doesn't have that either. onlyhelp test
does. Does that mean it is abash
specific file existence testing?
– xpt
Jun 17 '14 at 3:57
1
@xpt It would seem like that is the case, but for me/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.
– BenjiWiebe
Jun 17 '14 at 12:13
add a comment |
I am not sure why the info
page doesn't have it, but running help test
in bash
gives the answer:
...
File operators:
-a FILE True if file exists.
...
So it is simply an "existence" test, no other permissions/attributes checked.
I am not sure why the info
page doesn't have it, but running help test
in bash
gives the answer:
...
File operators:
-a FILE True if file exists.
...
So it is simply an "existence" test, no other permissions/attributes checked.
answered Jun 17 '14 at 1:42
BenjiWiebeBenjiWiebe
6,74093558
6,74093558
Perfect! Thanks. Strange,man test
doesn't have that either. onlyhelp test
does. Does that mean it is abash
specific file existence testing?
– xpt
Jun 17 '14 at 3:57
1
@xpt It would seem like that is the case, but for me/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.
– BenjiWiebe
Jun 17 '14 at 12:13
add a comment |
Perfect! Thanks. Strange,man test
doesn't have that either. onlyhelp test
does. Does that mean it is abash
specific file existence testing?
– xpt
Jun 17 '14 at 3:57
1
@xpt It would seem like that is the case, but for me/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.
– BenjiWiebe
Jun 17 '14 at 12:13
Perfect! Thanks. Strange,
man test
doesn't have that either. only help test
does. Does that mean it is a bash
specific file existence testing?– xpt
Jun 17 '14 at 3:57
Perfect! Thanks. Strange,
man test
doesn't have that either. only help test
does. Does that mean it is a bash
specific file existence testing?– xpt
Jun 17 '14 at 3:57
1
1
@xpt It would seem like that is the case, but for me
/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.– BenjiWiebe
Jun 17 '14 at 12:13
@xpt It would seem like that is the case, but for me
/bin/test -a file
worked also...So why it isn't in the manpage I have NO idea.– BenjiWiebe
Jun 17 '14 at 12:13
add a comment |
If you're running test
or [
in bash
, it's actually probably the built-in version, and not the coreutils
version in /usr/bin
:
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
That said, it does appear that the coreutils version implements both -a
and -e
, with exactly the same behavior. Maybe -a
is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a
is supposed to be short for).
add a comment |
If you're running test
or [
in bash
, it's actually probably the built-in version, and not the coreutils
version in /usr/bin
:
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
That said, it does appear that the coreutils version implements both -a
and -e
, with exactly the same behavior. Maybe -a
is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a
is supposed to be short for).
add a comment |
If you're running test
or [
in bash
, it's actually probably the built-in version, and not the coreutils
version in /usr/bin
:
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
That said, it does appear that the coreutils version implements both -a
and -e
, with exactly the same behavior. Maybe -a
is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a
is supposed to be short for).
If you're running test
or [
in bash
, it's actually probably the built-in version, and not the coreutils
version in /usr/bin
:
$ type test
test is a shell builtin
$ type [
[ is a shell builtin
That said, it does appear that the coreutils version implements both -a
and -e
, with exactly the same behavior. Maybe -a
is not reflected in the manpage because it's not standard, so maybe it was added later and that person neglected to update the manpage accordingly. But I can't say I know the history behind why it was added (or even what the a
is supposed to be short for).
answered Jun 17 '14 at 5:17
jjlinjjlin
11.9k33842
11.9k33842
add a comment |
add a comment |
-a
is the AND operator for combining conditions, so the following shows yes if both directories exist:
[ -e /root -a -e /usr ] && echo yes
The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.
Reference (scroll down some after info coreutils 'test invocation'
):
16.3.6 Connectives for `test'
The usual logical connectives.
`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'
True if either EXPR1 or EXPR2 is true.
1
If you look at the coreutils source, thea
ande
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.
– jjlin
Jun 17 '14 at 17:33
add a comment |
-a
is the AND operator for combining conditions, so the following shows yes if both directories exist:
[ -e /root -a -e /usr ] && echo yes
The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.
Reference (scroll down some after info coreutils 'test invocation'
):
16.3.6 Connectives for `test'
The usual logical connectives.
`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'
True if either EXPR1 or EXPR2 is true.
1
If you look at the coreutils source, thea
ande
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.
– jjlin
Jun 17 '14 at 17:33
add a comment |
-a
is the AND operator for combining conditions, so the following shows yes if both directories exist:
[ -e /root -a -e /usr ] && echo yes
The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.
Reference (scroll down some after info coreutils 'test invocation'
):
16.3.6 Connectives for `test'
The usual logical connectives.
`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'
True if either EXPR1 or EXPR2 is true.
-a
is the AND operator for combining conditions, so the following shows yes if both directories exist:
[ -e /root -a -e /usr ] && echo yes
The use of it with a single condition that defaults to an existance test seems like retained old behavior but I can't find it in old man pages.
Reference (scroll down some after info coreutils 'test invocation'
):
16.3.6 Connectives for `test'
The usual logical connectives.
`! EXPR'
True if EXPR is false.
`EXPR1 -a EXPR2'
True if both EXPR1 and EXPR2 are true.
`EXPR1 -o EXPR2'
True if either EXPR1 or EXPR2 is true.
edited Dec 24 '17 at 14:56
answered Jun 17 '14 at 13:46
BrianBrian
8,2511833
8,2511833
1
If you look at the coreutils source, thea
ande
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.
– jjlin
Jun 17 '14 at 17:33
add a comment |
1
If you look at the coreutils source, thea
ande
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.
– jjlin
Jun 17 '14 at 17:33
1
1
If you look at the coreutils source, the
a
and e
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.– jjlin
Jun 17 '14 at 17:33
If you look at the coreutils source, the
a
and e
cases share the same code in the function that handles unary operators, so I don't think it's an accidental thing.– jjlin
Jun 17 '14 at 17:33
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f769670%2fwhats-linux-test-a-command-test-for%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