I have a Bash script that returns a command. I would like to execute the script and let it automatically print the result behind the prompt in the next line. Replacing the script call in the current line would be an option too. This way I could edit the command before I execute it. Can this be achieved within a terminal with Bash?
From the bash manual: The backslash character '\' may be used to remove any special meaning for the next character read and for line continuation.
The Windows command prompt (cmd.exe) allows the ^ (Shift + 6) character to be used to indicate line continuation.
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc.
If you run bash within tmux (terminal multiplexer), you can use its buffer functions to paste a command at your prompt. You can then edit the command before running it. Here's a trivial example:
#!/bin/bash
tmux set-buffer 'ls -l'
tmux paste-buffer &
Putting the paste-buffer command in the background let's bash output the prompt before the paste happens. If the paste happens too quickly, you can add a sub-second sleep like so:
#!/bin/bash
tmux set-buffer 'ls -l'
{ sleep .25; tmux paste-buffer; } &
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With