Trap, ERR, and echoing the error line
I'm trying to create some error reporting using a Trap to call a function on all errors:
Trap "_func" ERR
Is it possible to get what line the ERR signal was sent from? The shell is bash.
If I do that, I can read and report what command was used and log/perform some actions.
Or maybe I'm going at this all wrong?
I tested with the following:
#!/bin/bash
trap "ECHO $LINENO" ERR
echo hello | grep "asdf"
And $LINENO is returning 2. Not working.
bash shell-script error-handling trap
|
show 1 more comment
I'm trying to create some error reporting using a Trap to call a function on all errors:
Trap "_func" ERR
Is it possible to get what line the ERR signal was sent from? The shell is bash.
If I do that, I can read and report what command was used and log/perform some actions.
Or maybe I'm going at this all wrong?
I tested with the following:
#!/bin/bash
trap "ECHO $LINENO" ERR
echo hello | grep "asdf"
And $LINENO is returning 2. Not working.
bash shell-script error-handling trap
You can look at the bash debugger scriptbashdb. It seems that the first argument totrapcan contain variables that are evaluated in the desired context. Sotrap 'echo $LINENO' ERR'should work.
– donothingsuccessfully
May 29 '12 at 18:53
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
Sorry, I borked the example line:trap 'echo $LINENO' ERR. The first argument totrapis the entireecho $LINENOhardquoted. This is in bash.
– donothingsuccessfully
May 29 '12 at 19:43
4
@Mechaflash It would have to betrap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote,$LINENOis expanded when line 2 is parsed, so the trap isecho 2(or ratherECHO 2, which would outputbash: ECHO: command not found).
– Gilles
May 29 '12 at 23:56
|
show 1 more comment
I'm trying to create some error reporting using a Trap to call a function on all errors:
Trap "_func" ERR
Is it possible to get what line the ERR signal was sent from? The shell is bash.
If I do that, I can read and report what command was used and log/perform some actions.
Or maybe I'm going at this all wrong?
I tested with the following:
#!/bin/bash
trap "ECHO $LINENO" ERR
echo hello | grep "asdf"
And $LINENO is returning 2. Not working.
bash shell-script error-handling trap
I'm trying to create some error reporting using a Trap to call a function on all errors:
Trap "_func" ERR
Is it possible to get what line the ERR signal was sent from? The shell is bash.
If I do that, I can read and report what command was used and log/perform some actions.
Or maybe I'm going at this all wrong?
I tested with the following:
#!/bin/bash
trap "ECHO $LINENO" ERR
echo hello | grep "asdf"
And $LINENO is returning 2. Not working.
bash shell-script error-handling trap
bash shell-script error-handling trap
edited May 29 '12 at 23:55
Gilles
540k12810941609
540k12810941609
asked May 29 '12 at 18:23
MechaflashMechaflash
4923815
4923815
You can look at the bash debugger scriptbashdb. It seems that the first argument totrapcan contain variables that are evaluated in the desired context. Sotrap 'echo $LINENO' ERR'should work.
– donothingsuccessfully
May 29 '12 at 18:53
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
Sorry, I borked the example line:trap 'echo $LINENO' ERR. The first argument totrapis the entireecho $LINENOhardquoted. This is in bash.
– donothingsuccessfully
May 29 '12 at 19:43
4
@Mechaflash It would have to betrap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote,$LINENOis expanded when line 2 is parsed, so the trap isecho 2(or ratherECHO 2, which would outputbash: ECHO: command not found).
– Gilles
May 29 '12 at 23:56
|
show 1 more comment
You can look at the bash debugger scriptbashdb. It seems that the first argument totrapcan contain variables that are evaluated in the desired context. Sotrap 'echo $LINENO' ERR'should work.
– donothingsuccessfully
May 29 '12 at 18:53
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
Sorry, I borked the example line:trap 'echo $LINENO' ERR. The first argument totrapis the entireecho $LINENOhardquoted. This is in bash.
– donothingsuccessfully
May 29 '12 at 19:43
4
@Mechaflash It would have to betrap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote,$LINENOis expanded when line 2 is parsed, so the trap isecho 2(or ratherECHO 2, which would outputbash: ECHO: command not found).
– Gilles
May 29 '12 at 23:56
You can look at the bash debugger script
bashdb. It seems that the first argument to trap can contain variables that are evaluated in the desired context. So trap 'echo $LINENO' ERR' should work.– donothingsuccessfully
May 29 '12 at 18:53
You can look at the bash debugger script
bashdb. It seems that the first argument to trap can contain variables that are evaluated in the desired context. So trap 'echo $LINENO' ERR' should work.– donothingsuccessfully
May 29 '12 at 18:53
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
Sorry, I borked the example line:
trap 'echo $LINENO' ERR. The first argument to trap is the entire echo $LINENO hardquoted. This is in bash.– donothingsuccessfully
May 29 '12 at 19:43
Sorry, I borked the example line:
trap 'echo $LINENO' ERR. The first argument to trap is the entire echo $LINENO hardquoted. This is in bash.– donothingsuccessfully
May 29 '12 at 19:43
4
4
@Mechaflash It would have to be
trap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote, $LINENO is expanded when line 2 is parsed, so the trap is echo 2 (or rather ECHO 2, which would output bash: ECHO: command not found).– Gilles
May 29 '12 at 23:56
@Mechaflash It would have to be
trap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote, $LINENO is expanded when line 2 is parsed, so the trap is echo 2 (or rather ECHO 2, which would output bash: ECHO: command not found).– Gilles
May 29 '12 at 23:56
|
show 1 more comment
3 Answers
3
active
oldest
votes
As pointed out in comments, your quoting is wrong. You need single quotes to prevent $LINENO from being expanded when the trap line is first parsed.
This works:
#! /bin/bash
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
echo hello | grep foo # This is line number 9
Running it:
$ ./test.sh
Error on line 9
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foodoesn't seem to throw error for me. Am I misunderstanding something?
– geotheory
Dec 2 '15 at 22:15
@geotheory On my systemgrephas an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system withecho hello | grep foo; echo $?
– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
|
show 3 more comments
You can also use the bash builtin 'caller':
#!/bin/bash
err_report() {
echo "errexit on line $(caller)" >&2
}
trap err_report ERR
echo hello | grep foo
it prints filename too:
$ ./test.sh
errexit on line 9 ./test.sh
add a comment |
I really like the answer given by @Mat above. Building on this, I wrote a little helper which gives a bit more context for the error:
We can inspect the script for the line which caused the failure:
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
Here it is in a small test script:
#!/bin/bash
set -e
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
echo one
echo two
echo three
echo four
false
echo five
echo six
echo seven
echo eight
When we run it we get:
$ /tmp/test.sh
one
two
three
four
Error occurred:
12 echo two
13 echo three
14 echo four
15 >>>false
16 echo five
17 echo six
18 echo seven
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%2f39623%2ftrap-err-and-echoing-the-error-line%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
As pointed out in comments, your quoting is wrong. You need single quotes to prevent $LINENO from being expanded when the trap line is first parsed.
This works:
#! /bin/bash
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
echo hello | grep foo # This is line number 9
Running it:
$ ./test.sh
Error on line 9
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foodoesn't seem to throw error for me. Am I misunderstanding something?
– geotheory
Dec 2 '15 at 22:15
@geotheory On my systemgrephas an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system withecho hello | grep foo; echo $?
– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
|
show 3 more comments
As pointed out in comments, your quoting is wrong. You need single quotes to prevent $LINENO from being expanded when the trap line is first parsed.
This works:
#! /bin/bash
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
echo hello | grep foo # This is line number 9
Running it:
$ ./test.sh
Error on line 9
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foodoesn't seem to throw error for me. Am I misunderstanding something?
– geotheory
Dec 2 '15 at 22:15
@geotheory On my systemgrephas an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system withecho hello | grep foo; echo $?
– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
|
show 3 more comments
As pointed out in comments, your quoting is wrong. You need single quotes to prevent $LINENO from being expanded when the trap line is first parsed.
This works:
#! /bin/bash
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
echo hello | grep foo # This is line number 9
Running it:
$ ./test.sh
Error on line 9
As pointed out in comments, your quoting is wrong. You need single quotes to prevent $LINENO from being expanded when the trap line is first parsed.
This works:
#! /bin/bash
err_report() {
echo "Error on line $1"
}
trap 'err_report $LINENO' ERR
echo hello | grep foo # This is line number 9
Running it:
$ ./test.sh
Error on line 9
edited Nov 6 '15 at 15:38
community wiki
3 revs, 3 users 92%
Mat
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foodoesn't seem to throw error for me. Am I misunderstanding something?
– geotheory
Dec 2 '15 at 22:15
@geotheory On my systemgrephas an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system withecho hello | grep foo; echo $?
– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
|
show 3 more comments
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foodoesn't seem to throw error for me. Am I misunderstanding something?
– geotheory
Dec 2 '15 at 22:15
@geotheory On my systemgrephas an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system withecho hello | grep foo; echo $?
– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
thanks for the example with a function call. I didn't know that double quotes expanded the variable in this case.
– Mechaflash
May 30 '12 at 14:23
echo hello | grep foo doesn't seem to throw error for me. Am I misunderstanding something?– geotheory
Dec 2 '15 at 22:15
echo hello | grep foo doesn't seem to throw error for me. Am I misunderstanding something?– geotheory
Dec 2 '15 at 22:15
@geotheory On my system
grep has an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system with echo hello | grep foo; echo $?– Patrick
Dec 7 '15 at 23:17
@geotheory On my system
grep has an exit status of 0 if there was a match, 1 if there was no match and >1 for an error. You can check the behavior on your system with echo hello | grep foo; echo $?– Patrick
Dec 7 '15 at 23:17
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
No you're right it is an error :)
– geotheory
Dec 8 '15 at 9:56
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
Don't you need to use -e on the invocation line, to cause error on command failure? That is: #!/bin/bash -e ?
– Tim Bird
Mar 31 '17 at 22:39
|
show 3 more comments
You can also use the bash builtin 'caller':
#!/bin/bash
err_report() {
echo "errexit on line $(caller)" >&2
}
trap err_report ERR
echo hello | grep foo
it prints filename too:
$ ./test.sh
errexit on line 9 ./test.sh
add a comment |
You can also use the bash builtin 'caller':
#!/bin/bash
err_report() {
echo "errexit on line $(caller)" >&2
}
trap err_report ERR
echo hello | grep foo
it prints filename too:
$ ./test.sh
errexit on line 9 ./test.sh
add a comment |
You can also use the bash builtin 'caller':
#!/bin/bash
err_report() {
echo "errexit on line $(caller)" >&2
}
trap err_report ERR
echo hello | grep foo
it prints filename too:
$ ./test.sh
errexit on line 9 ./test.sh
You can also use the bash builtin 'caller':
#!/bin/bash
err_report() {
echo "errexit on line $(caller)" >&2
}
trap err_report ERR
echo hello | grep foo
it prints filename too:
$ ./test.sh
errexit on line 9 ./test.sh
answered Jul 4 '17 at 9:34
Andrew IvanovAndrew Ivanov
11112
11112
add a comment |
add a comment |
I really like the answer given by @Mat above. Building on this, I wrote a little helper which gives a bit more context for the error:
We can inspect the script for the line which caused the failure:
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
Here it is in a small test script:
#!/bin/bash
set -e
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
echo one
echo two
echo three
echo four
false
echo five
echo six
echo seven
echo eight
When we run it we get:
$ /tmp/test.sh
one
two
three
four
Error occurred:
12 echo two
13 echo three
14 echo four
15 >>>false
16 echo five
17 echo six
18 echo seven
add a comment |
I really like the answer given by @Mat above. Building on this, I wrote a little helper which gives a bit more context for the error:
We can inspect the script for the line which caused the failure:
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
Here it is in a small test script:
#!/bin/bash
set -e
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
echo one
echo two
echo three
echo four
false
echo five
echo six
echo seven
echo eight
When we run it we get:
$ /tmp/test.sh
one
two
three
four
Error occurred:
12 echo two
13 echo three
14 echo four
15 >>>false
16 echo five
17 echo six
18 echo seven
add a comment |
I really like the answer given by @Mat above. Building on this, I wrote a little helper which gives a bit more context for the error:
We can inspect the script for the line which caused the failure:
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
Here it is in a small test script:
#!/bin/bash
set -e
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
echo one
echo two
echo three
echo four
false
echo five
echo six
echo seven
echo eight
When we run it we get:
$ /tmp/test.sh
one
two
three
four
Error occurred:
12 echo two
13 echo three
14 echo four
15 >>>false
16 echo five
17 echo six
18 echo seven
I really like the answer given by @Mat above. Building on this, I wrote a little helper which gives a bit more context for the error:
We can inspect the script for the line which caused the failure:
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
Here it is in a small test script:
#!/bin/bash
set -e
err() {
echo "Error occurred:"
awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%sn",NR,(NR==L?">>>":""),$0 }' L=$1 $0
}
trap 'err $LINENO' ERR
echo one
echo two
echo three
echo four
false
echo five
echo six
echo seven
echo eight
When we run it we get:
$ /tmp/test.sh
one
two
three
four
Error occurred:
12 echo two
13 echo three
14 echo four
15 >>>false
16 echo five
17 echo six
18 echo seven
answered 46 mins ago
unpythonicunpythonic
68236
68236
add a comment |
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%2f39623%2ftrap-err-and-echoing-the-error-line%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
You can look at the bash debugger script
bashdb. It seems that the first argument totrapcan contain variables that are evaluated in the desired context. Sotrap 'echo $LINENO' ERR'should work.– donothingsuccessfully
May 29 '12 at 18:53
hmm just tried this with a bad echo | grep command and it returns the line of the Trap statement. But I'll take a look at bashdb
– Mechaflash
May 29 '12 at 18:56
I'm so sorry... I didn't specify in my original question that I need a native solution. I edited the question.
– Mechaflash
May 29 '12 at 19:05
Sorry, I borked the example line:
trap 'echo $LINENO' ERR. The first argument totrapis the entireecho $LINENOhardquoted. This is in bash.– donothingsuccessfully
May 29 '12 at 19:43
4
@Mechaflash It would have to be
trap 'echo $LINENO' ERR, with single quotes, not double quotes. With the command you wrote,$LINENOis expanded when line 2 is parsed, so the trap isecho 2(or ratherECHO 2, which would outputbash: ECHO: command not found).– Gilles
May 29 '12 at 23:56