write shell script similar history in console [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I try to write a simple script and store all my favor commands such as grep, find, sed.



when I use history command in shell, I can show all the historical commands with (history) I can reuse the the symbol '!'(Exclamation) to get my old commands:



Let's assume 2099 -> ls -lah (in my history)



>!2099 <- ENTER

>ls -la[CURSOR]


when I type '!2099 <- ENTER', 'ls -la[CURSOR]' in the next line.



does anyone know how to implement it on shell script?



I have tried to remove the 'r' from the input string, but it does't work so far.







share|improve this question












closed as unclear what you're asking by Michael Homer, Stephen Rauch, Romeo Ninov, Stephen Kitt, G-Man Dec 7 '17 at 0:38


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.


















    up vote
    -1
    down vote

    favorite












    I try to write a simple script and store all my favor commands such as grep, find, sed.



    when I use history command in shell, I can show all the historical commands with (history) I can reuse the the symbol '!'(Exclamation) to get my old commands:



    Let's assume 2099 -> ls -lah (in my history)



    >!2099 <- ENTER

    >ls -la[CURSOR]


    when I type '!2099 <- ENTER', 'ls -la[CURSOR]' in the next line.



    does anyone know how to implement it on shell script?



    I have tried to remove the 'r' from the input string, but it does't work so far.







    share|improve this question












    closed as unclear what you're asking by Michael Homer, Stephen Rauch, Romeo Ninov, Stephen Kitt, G-Man Dec 7 '17 at 0:38


    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.
















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I try to write a simple script and store all my favor commands such as grep, find, sed.



      when I use history command in shell, I can show all the historical commands with (history) I can reuse the the symbol '!'(Exclamation) to get my old commands:



      Let's assume 2099 -> ls -lah (in my history)



      >!2099 <- ENTER

      >ls -la[CURSOR]


      when I type '!2099 <- ENTER', 'ls -la[CURSOR]' in the next line.



      does anyone know how to implement it on shell script?



      I have tried to remove the 'r' from the input string, but it does't work so far.







      share|improve this question












      I try to write a simple script and store all my favor commands such as grep, find, sed.



      when I use history command in shell, I can show all the historical commands with (history) I can reuse the the symbol '!'(Exclamation) to get my old commands:



      Let's assume 2099 -> ls -lah (in my history)



      >!2099 <- ENTER

      >ls -la[CURSOR]


      when I type '!2099 <- ENTER', 'ls -la[CURSOR]' in the next line.



      does anyone know how to implement it on shell script?



      I have tried to remove the 'r' from the input string, but it does't work so far.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 6 '17 at 2:57









      Aron Lee

      162




      162




      closed as unclear what you're asking by Michael Homer, Stephen Rauch, Romeo Ninov, Stephen Kitt, G-Man Dec 7 '17 at 0:38


      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.






      closed as unclear what you're asking by Michael Homer, Stephen Rauch, Romeo Ninov, Stephen Kitt, G-Man Dec 7 '17 at 0:38


      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.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          The fc command allows you to edit and list commands from your history. This is useful when scripting anything related to history. List entries with:



          fc -ln [first] [last]


          -l is the list flag, -n prevents display of the history numbers, [first] and [last] are the numbers from the history command. To list a single command repeat its number. So using your example:



          cmd=$(fc -ln 2099 2099)
          echo "$cmd"


          will display ls -la. The output has a tab at the beginning so you can strip that off by piping fc through sed 's/^t//' or tr -d 't'






          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            The fc command allows you to edit and list commands from your history. This is useful when scripting anything related to history. List entries with:



            fc -ln [first] [last]


            -l is the list flag, -n prevents display of the history numbers, [first] and [last] are the numbers from the history command. To list a single command repeat its number. So using your example:



            cmd=$(fc -ln 2099 2099)
            echo "$cmd"


            will display ls -la. The output has a tab at the beginning so you can strip that off by piping fc through sed 's/^t//' or tr -d 't'






            share|improve this answer


























              up vote
              0
              down vote



              accepted










              The fc command allows you to edit and list commands from your history. This is useful when scripting anything related to history. List entries with:



              fc -ln [first] [last]


              -l is the list flag, -n prevents display of the history numbers, [first] and [last] are the numbers from the history command. To list a single command repeat its number. So using your example:



              cmd=$(fc -ln 2099 2099)
              echo "$cmd"


              will display ls -la. The output has a tab at the beginning so you can strip that off by piping fc through sed 's/^t//' or tr -d 't'






              share|improve this answer
























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                The fc command allows you to edit and list commands from your history. This is useful when scripting anything related to history. List entries with:



                fc -ln [first] [last]


                -l is the list flag, -n prevents display of the history numbers, [first] and [last] are the numbers from the history command. To list a single command repeat its number. So using your example:



                cmd=$(fc -ln 2099 2099)
                echo "$cmd"


                will display ls -la. The output has a tab at the beginning so you can strip that off by piping fc through sed 's/^t//' or tr -d 't'






                share|improve this answer














                The fc command allows you to edit and list commands from your history. This is useful when scripting anything related to history. List entries with:



                fc -ln [first] [last]


                -l is the list flag, -n prevents display of the history numbers, [first] and [last] are the numbers from the history command. To list a single command repeat its number. So using your example:



                cmd=$(fc -ln 2099 2099)
                echo "$cmd"


                will display ls -la. The output has a tab at the beginning so you can strip that off by piping fc through sed 's/^t//' or tr -d 't'







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 6 '17 at 3:16

























                answered Dec 6 '17 at 3:06









                B Layer

                3,9091525




                3,9091525












                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?