How to know the name of the last command that was executed? [on hold]











up vote
0
down vote

favorite












Let's say we run this script on Linux:



/tmp/start.sh


After running it, is there any way to retrieve the name of the last command executed?



expected output



start.sh









share|improve this question















put on hold as unclear what you're asking by Anthony Geoghegan, RalfFriedl, Romeo Ninov, Rui F Ribeiro, Jeff Schaller yesterday


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
    – terdon
    yesterday










  • yes I mean - the last command that executed
    – yael
    yesterday






  • 2




    @yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
    – Kusalananda
    yesterday






  • 1




    Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
    – ctrl-alt-delor
    yesterday






  • 1




    It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
    – terdon
    yesterday















up vote
0
down vote

favorite












Let's say we run this script on Linux:



/tmp/start.sh


After running it, is there any way to retrieve the name of the last command executed?



expected output



start.sh









share|improve this question















put on hold as unclear what you're asking by Anthony Geoghegan, RalfFriedl, Romeo Ninov, Rui F Ribeiro, Jeff Schaller yesterday


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
    – terdon
    yesterday










  • yes I mean - the last command that executed
    – yael
    yesterday






  • 2




    @yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
    – Kusalananda
    yesterday






  • 1




    Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
    – ctrl-alt-delor
    yesterday






  • 1




    It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
    – terdon
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Let's say we run this script on Linux:



/tmp/start.sh


After running it, is there any way to retrieve the name of the last command executed?



expected output



start.sh









share|improve this question















Let's say we run this script on Linux:



/tmp/start.sh


After running it, is there any way to retrieve the name of the last command executed?



expected output



start.sh






bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









terdon

127k31246423




127k31246423










asked yesterday









yael

2,37511958




2,37511958




put on hold as unclear what you're asking by Anthony Geoghegan, RalfFriedl, Romeo Ninov, Rui F Ribeiro, Jeff Schaller yesterday


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Anthony Geoghegan, RalfFriedl, Romeo Ninov, Rui F Ribeiro, Jeff Schaller yesterday


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
    – terdon
    yesterday










  • yes I mean - the last command that executed
    – yael
    yesterday






  • 2




    @yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
    – Kusalananda
    yesterday






  • 1




    Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
    – ctrl-alt-delor
    yesterday






  • 1




    It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
    – terdon
    yesterday


















  • Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
    – terdon
    yesterday










  • yes I mean - the last command that executed
    – yael
    yesterday






  • 2




    @yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
    – Kusalananda
    yesterday






  • 1




    Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
    – ctrl-alt-delor
    yesterday






  • 1




    It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
    – terdon
    yesterday
















Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
– terdon
yesterday




Do you mean the last commnd to be executed or specifically the last shell script? If you run /tmp/start.sh; ls will you want ls as output or start.sh?
– terdon
yesterday












yes I mean - the last command that executed
– yael
yesterday




yes I mean - the last command that executed
– yael
yesterday




2




2




@yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
– Kusalananda
yesterday




@yael Huh? Could you elaborate on what it is that you actually want to do, exactly? Please do so in the question itself.
– Kusalananda
yesterday




1




1




Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
– ctrl-alt-delor
yesterday




Can you explain what you are trying to do. This seems like an AB question. That is you are trying to do A, can see that you can do it via B, and ask how to do B. It may be easier to just do A.
– ctrl-alt-delor
yesterday




1




1




It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
– terdon
yesterday




It really isn't simple. For one thing, how do you define previous? What if another user ran something in a different session? What if the same user ran something but in a different session (e.g. another terminal)? Which command should be found then?
– terdon
yesterday










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Using history expansion in an interactive bash shell:



$ /some/path/script.sh




$ printf 'Basename of last command line: %sn' "$(basename "!!")"
printf 'Basename of last command line: %sn' "$(basename "/some/path/script.sh")"
Basename of last command line: script.sh


The !! is a history expansion event designator, which will be replaced by the last command. See the "HISTORY EXPANSION" section in your bash manual.



Note that !! will expand to the full command line.





In a shell script, you always know what the previous script was called, because you just typed it in.



/some/path/script.sh

echo 'script.sh just finished'





share|improve this answer























  • Note also that this will only work in an interactive shell.
    – terdon
    yesterday


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Using history expansion in an interactive bash shell:



$ /some/path/script.sh




$ printf 'Basename of last command line: %sn' "$(basename "!!")"
printf 'Basename of last command line: %sn' "$(basename "/some/path/script.sh")"
Basename of last command line: script.sh


The !! is a history expansion event designator, which will be replaced by the last command. See the "HISTORY EXPANSION" section in your bash manual.



Note that !! will expand to the full command line.





In a shell script, you always know what the previous script was called, because you just typed it in.



/some/path/script.sh

echo 'script.sh just finished'





share|improve this answer























  • Note also that this will only work in an interactive shell.
    – terdon
    yesterday















up vote
2
down vote













Using history expansion in an interactive bash shell:



$ /some/path/script.sh




$ printf 'Basename of last command line: %sn' "$(basename "!!")"
printf 'Basename of last command line: %sn' "$(basename "/some/path/script.sh")"
Basename of last command line: script.sh


The !! is a history expansion event designator, which will be replaced by the last command. See the "HISTORY EXPANSION" section in your bash manual.



Note that !! will expand to the full command line.





In a shell script, you always know what the previous script was called, because you just typed it in.



/some/path/script.sh

echo 'script.sh just finished'





share|improve this answer























  • Note also that this will only work in an interactive shell.
    – terdon
    yesterday













up vote
2
down vote










up vote
2
down vote









Using history expansion in an interactive bash shell:



$ /some/path/script.sh




$ printf 'Basename of last command line: %sn' "$(basename "!!")"
printf 'Basename of last command line: %sn' "$(basename "/some/path/script.sh")"
Basename of last command line: script.sh


The !! is a history expansion event designator, which will be replaced by the last command. See the "HISTORY EXPANSION" section in your bash manual.



Note that !! will expand to the full command line.





In a shell script, you always know what the previous script was called, because you just typed it in.



/some/path/script.sh

echo 'script.sh just finished'





share|improve this answer














Using history expansion in an interactive bash shell:



$ /some/path/script.sh




$ printf 'Basename of last command line: %sn' "$(basename "!!")"
printf 'Basename of last command line: %sn' "$(basename "/some/path/script.sh")"
Basename of last command line: script.sh


The !! is a history expansion event designator, which will be replaced by the last command. See the "HISTORY EXPANSION" section in your bash manual.



Note that !! will expand to the full command line.





In a shell script, you always know what the previous script was called, because you just typed it in.



/some/path/script.sh

echo 'script.sh just finished'






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Kusalananda

120k16225370




120k16225370












  • Note also that this will only work in an interactive shell.
    – terdon
    yesterday


















  • Note also that this will only work in an interactive shell.
    – terdon
    yesterday
















Note also that this will only work in an interactive shell.
– terdon
yesterday




Note also that this will only work in an interactive shell.
– terdon
yesterday



Popular posts from this blog

サソリ

広島県道265号伴広島線

Setup Asymptote in Texstudio