two bash scripting questions

gerrynix gerrynix at yahoo.com
Mon Feb 14 18:14:07 UTC 2005


--- Mark Knecht <markknecht at gmail.com> wrote:

> Hi,
>    I've built a little bash script that does some music stuff for me
> in Gnome. I've set a mime type in Gnome so that I can click on certain
> files, a terminal opens, the script runs, I answer some questions and
> the script makes the music server do some things. It works well, as
> far as it goes, but there are a couple of things I couldn't figure out
> on Sunday.
> 
> 1) If I run a generic command that talks to a music server in a
> terminal I get a response of OK. I'd like to capture this OK, vs. the
> other possibilities or WARN or ERR, and take action based on that
> response. How can I do this in a script?
> 
> 2) In the case of the command that adds channels to my server I get a
> response that has the channel number buried in the OK, such as OK[3]
> telling me the ADD CHANNEL command completed and the new channel is
> number 3. How can I capture this number for use in the script? The
> normal command sequence here might look like
> 
> echo "ADD CHANNEL" | nc localhost 8888
> 
> and I receive 
> 
> OK[3] back in the terminal. I tried some things like
> 
> OUTPUT=`echo "ADD CHANNEL" | nc localhost 8888`
> 
> and
> 
> OUTPUT=$(echo "ADD CHANNEL" | nc localhost 8888)
> 
> but they didn't work.
> 
>    The script is small. It's attached in case there are better ways to
> do this stuff that people want to share.
> 
> Thanks much,
> Mark

I did not find your script attached.
Maybe not so eloquent, but this may give you some food for thought
and adaptable to your needs. I did this from the command line for
demo, but you could also use it in variable assignment with command
substitution as in your examples. Those are all single quotes in the
sed command and NO spaces anywhere inside the outside quotes. This
in effect "strips away the capitals O and K and square braces.

$ echo OK[3] | sed -g 's/'['']'[OK]//'
3
$
--
Nix
> 
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list at redhat.com
> https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request at redhat.com
> Subject: unsubscribe
> 




More information about the Redhat-install-list mailing list