I have below scenario and would like to know how to achieve

Run the shell script which has 2 commands, which should run sequentially. But the problem is when I run the first command, the prompt goes into the command that I executed and the second command never executes.


ade useview testview
ade refreshview -latest

exit ~


[ ~/cron_scripts]$ ./test.sh 
ade:[ testview ] $ 

So when the command 1 enters a view then shell script loose control and never executes second command

  • Could you please edit your question to show us your actual script and what happens when you run it, and also what you wish happened? – Eric Renouf Apr 14 '17 at 18:02
  • Shell scripts should be able to trivially run one command, then another after the first one completes. That's actually the main case of what they do! There should not be any business of "shell script loose [sic] control". Please show your shell script and how you are running it. – Celada Apr 14 '17 at 18:02
  • I have edited the post, hopefully its better now – ramesh Apr 14 '17 at 18:30
  • bash <<< "ls" runs bash “typing” in ls, however it does not keep the input open. May be someone can expand on it. – ctrl-alt-delor Apr 14 '17 at 19:58

Since the first command

ade useview testview

starts an interactive session, that session has to end before the next command in the script is run.

Once it ends, though, the script will run the second command. So it hasn't "lost control" completely, but is waiting for the interactive session of the first command to finish.

  • I want to run the second command in the interactive session. Is there any way to do that ? – ramesh Apr 14 '17 at 18:59
  • 1
    @ramesh Not knowing what ade is, I can't answer that properly. There may be, for example, some way of specifying a command for it to run, just as when one uses bash -c ls to start bash and instructing it to run ls. – Kusalananda Apr 14 '17 at 19:23
  • Thanks, ade is just an example. It could be anything where the commands starts an interactive session and if we want to run some commands in that session. Just trying to see if that's a achievable case in unix scripting. – ramesh Apr 14 '17 at 19:27
  • @ramesh It's definitely achievable, but it very much depends on how ade is operating. There's no general solution. Some interactive applications may read from standard input, other's from a file on the command line, and others, like bash will not enter interactive mode at all when given a command on the command line in the invoking shell session. You may want to look into using expect, but since my expect-fu is weak, I can't give a solution for that either. – Kusalananda Apr 14 '17 at 19:36
  • Thanks @Kusalananda, when i run the ade command , it enters the view and still accepts all the unix commands normally. – ramesh Apr 14 '17 at 21:02
ade useview -exec /full/path/of/the/file/subshellcommands.sh view_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.