Results 1 to 4 of 4
How can I get to know what command/script/function, I just called/ran within a script.
Code:
[stpuser@stpbuild]$ echo aaa
aaa
[stpuser@stpbuild]$ echo bbb
bbb
[stpuser@stpbuild]$ echo ccc
ccc
[stpuser@stpbuild]$ history|tail -1
...
- 06-09-2008 #1
Find Last command name within a shell script
How can I get to know what command/script/function, I just called/ran within a script.
What I want is that, a.sh should display "echo ccc" as it is the last command that was executed before the last command in a.sh script.Code:[stpuser@stpbuild]$ echo aaa aaa [stpuser@stpbuild]$ echo bbb bbb [stpuser@stpbuild]$ echo ccc ccc [stpuser@stpbuild]$ history|tail -1 34 echo ccc [stpuser@stpbuild]$ cat a.sh echo aaa echo bbb echo ccc history |tail -1 [stpuser@stpbuild]$ ./a.sh aaa bbb ccc [stpuser@stpbuild]$ . ./a.sh aaa bbb ccc 37 ./a.sh [stpuser@stpbuild]$
Any helps!
- 06-10-2008 #2Just Joined!
- Join Date
- Jun 2008
- Posts
- 39
This does not exactly answer your question, but if you use "history 2" it will give you something close.
history: usage: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...]
- 07-22-2008 #3
$LINENO can be useful (if we embed that in our script line) provided, there should not be multiple commands (separated by ";" semi-colon) in one line.
- 07-22-2008 #4
$LINENO can be useful (if we embed that in our script line) provided, there should not be multiple commands (separated by ";" semi-colon) in one line.


Reply With Quote