LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-23-2006, 10:35 AM   #1
danreed007
LQ Newbie
 
Registered: Aug 2004
Posts: 21

Rep: Reputation: 15
BASH scripting problem


Hi

Im starting to write BASH scripts to automate some of my analysis. Ive been trying to find out how to do something but I cannot find it on the web or in books so could any of you pros please help me...

Basically, in my script I execute an analysis program which opens up its own command line within which I type analysis commands, then I exit to return back to the bash prompt, like so:

~> program #start program

program> command1 #Enter program commands
program> command2
program> exit #Exit program, back to bash shell

~>

The problem is that I dont how to script all this in bash, i.e. enter all the external commands for my analysis program and exit the program subshell. Can any of you help.

I came across something that apparently works in tcsh, the 'comm' parameter is used to supply external commands, it would go like this:

~> program comm="command1 & command2 & exit"

Could any of you please help, and give me advice on how to do it in bash?

Thanks
 
Old 04-23-2006, 10:46 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
try redirecting input:
Code:
prog <file
prog <<EOF
cmd
exit
EOF
prog <<<'cmd
exit';
 
Old 04-23-2006, 02:33 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I've never used expect before, but I believe this kind of thing is what it was written to address.

Expect
 
Old 04-24-2006, 03:38 AM   #4
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Never mind.

Last edited by /bin/bash; 04-24-2006 at 03:40 AM. Reason: Oops didn't read carefully.
 
Old 04-24-2006, 04:51 AM   #5
danreed007
LQ Newbie
 
Registered: Aug 2004
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks for your help guys but I managed to find a solution and its quite simple. From within the script I call 'program' and it requires two arguments, name of an input file and the name of the output file it will produce, it then proceeds to its command line interface where I enter my analysis commands, cmd1, cmd2 and then exit:

Code:
 program infile outfile comm="cmd1 && cmd2 && exit"

Once the program is called and its command line interface is opened, 'cmd1', 'cmd2' and then 'exit' are entered sequentially.

I actually thought that the 'comm' parameter, used above, was a bash builtin function or something but it is not, because the following also works:

Code:
 program infile outfile "cmd1 && cmd2 && exit"

So now, Im really confused. I dont understand why the declaration 'comm=...' works as input to the program interface, or why just giving the quoted string with logical && operators works? Can any you explain the semantics of this and what exactly bash is "thinking" when it does it?

Thanks all
 
Old 04-24-2006, 05:02 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
What the program is? Looks like it is smart enough, so everything is passed as _arguments_ (not input) to the program and it manages to understand what do you want.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting problem sutley Linux - Software 1 12-17-2004 11:33 AM
bash scripting problem Sammy2ooo Linux - General 3 12-13-2004 12:31 PM
BASH Scripting Design Problem... amaze Linux - General 1 08-19-2003 08:30 AM
BASH scripting problem deadlock Programming 5 08-15-2003 04:33 AM
bash scripting problem raven Programming 7 03-10-2003 05:48 PM


All times are GMT -5. The time now is 03:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration