You are not logged in.
Pages: 1
Topic closed
So, we all know that !! will execute the previous command from the Command Line.
We also know that !-n will execute the previous whatever-th command, where "n" is a number, from the Command Line.
But neither of these work inside of a bash script. How would I go about doing this inside of a bash script?
Offline
Smells like an x-y question, but: if you really want to run the same command multiple times in a row, use a loop. If you want to run the same command (or set of commands) from earlier, put it in a function and call that.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Smells like an x-y question, but: if you really want to run the same command multiple times in a row, use a loop. If you want to run the same command (or set of commands) from earlier, put it in a function and call that.
That would be the obvious solution, but for this I need to call back to commands executed on a timeline, not by function names.
Offline
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Because I need "Command 2" to go back to the original command that executed it, which can come from several other different commands.
Offline
Stop giving awkwardly vague descriptions - post your actual code.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Stop giving awkwardly vague descriptions - post your actual code.
I'll post code if you can actually answer the original question. Without referring to a specifically named function, can previously executed commands be recalled in a fashion similar to using !-n inside of a bash script, or not? Because if it's not possible, I'll fix it a different way, I just didn't want to.
Last edited by Tx86 (2023-10-09 01:53:10)
Offline
Let me guess, this is related to package management and you don't want to post it because it's not actually Arch Linux?
Online
Let me guess, this is related to package management and you don't want to post it because it's not actually Arch Linux?
No. I mean, you're right, I'm not actually using Arch right now, but that's not why I want to post it. I just want the question answered.
Offline
Scimmia wrote:Let me guess, this is related to package management and you don't want to post it because it's not actually Arch Linux?
No. I mean, you're right, I'm not actually using Arch right now, but that's not why I want to post it. I just want the question answered.
And yet https://terms.archlinux.org/docs/code-o … pport-only
Online
It's literally just a bash script.
Offline
Just append -i option inside your bash script.
$: cat /usr/local/bin/history.verify
#!/usr/sbin/bash -i
date;
id;
fc -l
!!
!-2
Offline
Just append -i option inside your bash script.
$: cat /usr/local/bin/history.verify #!/usr/sbin/bash -i date; id; fc -l !! !-2
Thanks for the effort, but it unfortunately doesn't work. It's fine. I'll just do it the hard way, even though I really didn't want to. But thank for actually giving me an answer instead of dancing around the question.
Offline
This works in a normal Linux distro, if your distro or enviroment are special. Please let us known, so that people can help you.
Offline
This works in a normal Linux distro, if your distro or enviroment are special. Please let us known, so that people can help you.
It's not. Again, thank you for your time.
Offline
Topic closed...
Offline
Pages: 1
Topic closed