write shell script similar history in console [closed]
Clash 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.
shell history
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.
add a comment |Â
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.
shell history
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.
add a comment |Â
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.
shell history
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.
shell history
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.
add a comment |Â
add a comment |Â
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'
add a comment |Â
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'
add a comment |Â
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'
add a comment |Â
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'
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'
edited Dec 6 '17 at 3:16
answered Dec 6 '17 at 3:06
B Layer
3,9091525
3,9091525
add a comment |Â
add a comment |Â