I have a script that reads a line from a file into variable foo. The line is in fact a long command that I often use as a template. I am trying to edit and re-use this long command. How can I place $foo on the command line ready to edit? I do not want to copy and paste the line, nor do I want to use any new apps that need installing such as xdotool. I only want to use the basic Linux commands if possible.
The method with partial success is to append the line to the .bash_history file and then recall it in the usual way. But to do this I need to close the terminal and re-open it (so that the latest copy of the history file is loaded to RAM).
echo $foo
to place the command in the history and then recall and edit it as I see fit. Doesn't work well if you have new lines, quotes, etc. in the command. – doneal24 Nov 19 '21 at 23:09history -n
. Runhelp history
for details. 2. why not just write a script or a function using positional parameters ($1, $2, etc) instead of a hard-coded template that needs to be manually edited?