&> test or > test 2>&1
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I read from an instruction using &>
to handle errors and data
$ls -al test test2 test3 badtest &> test7
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]
It recommends 2>&1
$ ls -al test test2 test3 badtest > test7 2>&1
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Which pattern should I follow
bash
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I read from an instruction using &>
to handle errors and data
$ls -al test test2 test3 badtest &> test7
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]
It recommends 2>&1
$ ls -al test test2 test3 badtest > test7 2>&1
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Which pattern should I follow
bash
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I read from an instruction using &>
to handle errors and data
$ls -al test test2 test3 badtest &> test7
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]
It recommends 2>&1
$ ls -al test test2 test3 badtest > test7 2>&1
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Which pattern should I follow
bash
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I read from an instruction using &>
to handle errors and data
$ls -al test test2 test3 badtest &> test7
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Nonetheless, when I check Obsolete and deprecated syntax [Bash Hackers Wiki]
It recommends 2>&1
$ ls -al test test2 test3 badtest > test7 2>&1
$ cat test7
ls: cannot access 'test': No such file or directory
ls: cannot access 'badtest': No such file or directory
-rw-r--r-- 1 me staff 78 Oct 28 19:07 test2
-rw-r--r-- 1 me staff 0 Oct 28 19:03 test3
Which pattern should I follow
bash
bash
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 47 mins ago
avirate
39329
39329
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
avirate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
This is up to you to decide.
The bash
shell understands &>file
and >file 2>&1
as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>
.
If you only write bash
scripts (and not scripts for e.g. /bin/sh
), then by all means use &>
, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh
or that should be executable by any sh
-like shell, of which bash
is one and ksh
, zsh
and dash
are others), then &>
is one of the things you should avoid.
All sh
-like shells implement the POSIX standard in terms of syntax and grammar, but bash
and other shells also provides syntactic conveniences like &>
and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash
is doing it.
Related:
Other questions on this site aboutbash
and portability (DuckDuckGo search link).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
This is up to you to decide.
The bash
shell understands &>file
and >file 2>&1
as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>
.
If you only write bash
scripts (and not scripts for e.g. /bin/sh
), then by all means use &>
, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh
or that should be executable by any sh
-like shell, of which bash
is one and ksh
, zsh
and dash
are others), then &>
is one of the things you should avoid.
All sh
-like shells implement the POSIX standard in terms of syntax and grammar, but bash
and other shells also provides syntactic conveniences like &>
and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash
is doing it.
Related:
Other questions on this site aboutbash
and portability (DuckDuckGo search link).
add a comment |Â
up vote
4
down vote
accepted
This is up to you to decide.
The bash
shell understands &>file
and >file 2>&1
as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>
.
If you only write bash
scripts (and not scripts for e.g. /bin/sh
), then by all means use &>
, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh
or that should be executable by any sh
-like shell, of which bash
is one and ksh
, zsh
and dash
are others), then &>
is one of the things you should avoid.
All sh
-like shells implement the POSIX standard in terms of syntax and grammar, but bash
and other shells also provides syntactic conveniences like &>
and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash
is doing it.
Related:
Other questions on this site aboutbash
and portability (DuckDuckGo search link).
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
This is up to you to decide.
The bash
shell understands &>file
and >file 2>&1
as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>
.
If you only write bash
scripts (and not scripts for e.g. /bin/sh
), then by all means use &>
, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh
or that should be executable by any sh
-like shell, of which bash
is one and ksh
, zsh
and dash
are others), then &>
is one of the things you should avoid.
All sh
-like shells implement the POSIX standard in terms of syntax and grammar, but bash
and other shells also provides syntactic conveniences like &>
and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash
is doing it.
Related:
Other questions on this site aboutbash
and portability (DuckDuckGo search link).
This is up to you to decide.
The bash
shell understands &>file
and >file 2>&1
as identical and you may use the former syntax as a shortcut way of writing the latter. Other shells may throw a syntax error or do something unexpected with &>
.
If you only write bash
scripts (and not scripts for e.g. /bin/sh
), then by all means use &>
, but if you find yourself wanting or needing to write portable scripts (scripts that need to run under /bin/sh
or that should be executable by any sh
-like shell, of which bash
is one and ksh
, zsh
and dash
are others), then &>
is one of the things you should avoid.
All sh
-like shells implement the POSIX standard in terms of syntax and grammar, but bash
and other shells also provides syntactic conveniences like &>
and extensions like arrays and regular expression matching etc., and some shells may expand on the POSIX standard quite differently from the way bash
is doing it.
Related:
Other questions on this site aboutbash
and portability (DuckDuckGo search link).
edited 1 min ago
answered 39 mins ago


Kusalananda
112k15216343
112k15216343
add a comment |Â
add a comment |Â
avirate is a new contributor. Be nice, and check out our Code of Conduct.
avirate is a new contributor. Be nice, and check out our Code of Conduct.
avirate is a new contributor. Be nice, and check out our Code of Conduct.
avirate is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478238%2ftest-or-test-21%23new-answer', 'question_page');
);
Post as a guest
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
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
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