0

I run multiple bash script for FFmpeg. However, since I have several windows open, I lose track of what file I ran since I execute the file directly from the script there is no history of what I ran. The only history there is the first file I called

for example:

enter tv number i.e 19: 19
 stream key: key
 Press [enter] to execute tv19

I press enter, and it runs tv19 but there is no record I ran tv19 in that window, so how can I echo the command to the $

like this

[ibrod ~]$ ./tv19

than I can press enter and use the up arrow than I know what file I ran in that putty window.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Slightz
  • 67
  • 9
  • See http://stackoverflow.com/questions/2853803/in-a-shell-script-echo-shell-commands-as-they-are-executed – Philip Tzou Oct 22 '16 at 04:29
  • This appears to be an exact duplicate of the SuperUser question [Populate command line from script](http://superuser.com/questions/1023185/populate-command-line-from-script). – Charles Duffy Oct 22 '16 at 04:34
  • @PhilipTzou, echoing commands as they're executed is not what the OP is actually trying to accomplish here. ("`echo`" is a rather misleading choice of terms, in that respect). I've tried to edit the title to make the question clearer. I **do** recall having seen this question here on SO vs SU, so I'm sure that there is an on-site dupe, but that one's not it. – Charles Duffy Oct 22 '16 at 04:38
  • @Slightz, ...in general: No external program (and a script that's executed as opposed to sourced is very much an external program) can modify the internal state of the interpreter that calls it -- and history is internal state, as is the shell's understanding of its prompt. Now, you could have a shell **function** that played with history -- maybe writing arbitrary content and using `histfile -r` to force it to be reread -- but an external script? Nope, not possible (in a sane, portable and supported manner); you'll end up doing things like playing tricks with the clipboard instead. – Charles Duffy Oct 22 '16 at 04:44
  • @CharlesDuffy thanks, I was not sure how to ask properly. What I want is the command be printed in the $ área so I just press enter and there will be a hoistory. Echo the command does not help since FFmpeg will overwrite clear the output with its encoding log. – Slightz Oct 22 '16 at 04:51
  • @Slightz, echoing the command wouldn't help you get content into the history even if ffmpeg *didn't* write subsequent logs to the console. The overriding issue here is that you want to modify state that belongs to your parent process from a subprocess, and that's not something UNIX generally allows. – Charles Duffy Oct 22 '16 at 05:01
  • @Slightz, ...now, if you *do* want to just log that at the end, well, add another line at the end, *after* you run `tv19` from your script, that logs to the user a description of what it finished running. – Charles Duffy Oct 22 '16 at 05:02
  • @Slightz, ...keep in mind, though: even if you write to the terminal in such a way as to make it look like `./tv19` was run as a command by the parent shell, bash *doesn't know* what was written to the terminal by any program other than, well, bash -- so doing so won't change what's in the command history in any way. – Charles Duffy Oct 22 '16 at 05:03
  • two things to try adding to the end of your interactive script: `history -s ./tv19`, or `env PS1='./tv19 $ ' bash --norc`. (neither one does exactly what you asked for, but might help nonetheless.) – webb Oct 22 '16 at 08:34

1 Answers1

-1

Thanks for the help, I figured another way. I change the prompt like [tv10 ~]$

just made a file changetv i put inside

PS1="[$1 \W]\$ "

so I run the file and call it as

. ./changetv tv10

so now I know what window is what. :)

Slightz
  • 67
  • 9