LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-06-2013, 01:42 PM   #1
rehan21
Member
 
Registered: May 2009
Location: Karachi, Pakistan
Distribution: Centos 5.1/Fedora 10/ubuntu
Posts: 41

Rep: Reputation: 15
output from bash script as an argument??????


Hi Every one,

How to take output from bash script as an argument?

Regards,
Rehan
 
Old 02-06-2013, 01:48 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,695

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by rehan21 View Post
Hi Every one,
How to take output from bash script as an argument?
You write your script to read it, that's how. Putting "how to use output from one bash script as input to another" into Google pulls up lots of solutions...have you tried that?
http://stackoverflow.com/questions/1...another-script
http://www.unix.com/shell-programmin...t-another.html

There are different ways to do it, depending on what the first script returns, and how. Also, you need to take into account that STDERR is different than STDOUT, and do you want to capture both, or just one?
 
Old 02-06-2013, 06:50 PM   #3
drunkenbrawler
LQ Newbie
 
Registered: Sep 2009
Location: FL, United States
Distribution: Ubuntu Fedora
Posts: 10

Rep: Reputation: 0
Yeah, it will depend on what your first script outputs and what the second script wants to do.

In general, you can pipe the output of the first and 'read' it in second script. You can also use 'xargs' (check man page).
 
Old 02-07-2013, 03:22 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
how can I write a bash script to tell me the winner of the 4:30 at Kempton Park?
 
Old 02-07-2013, 05:07 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by bigearsbilly View Post
how can I write a bash script to tell me the winner of the 4:30 at Kempton Park?
Simple:
Code:
#!/bin/bash

wget -O /tmp/fixed.txt http://match.fixing.cn/.hidden/winners/fixed.matches.txt

grep "Kempton Park" /tmp/fixed.txt | grep "4:30"
 
Old 02-08-2013, 11:28 PM   #6
rehan21
Member
 
Registered: May 2009
Location: Karachi, Pakistan
Distribution: Centos 5.1/Fedora 10/ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by drunkenbrawler View Post
Yeah, it will depend on what your first script outputs and what the second script wants to do.

In general, you can pipe the output of the first and 'read' it in second script. You can also use 'xargs' (check man page).
Any example would u like to give ?

Regards,
Rehan
 
Old 02-09-2013, 04:01 AM   #7
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by rehan21 View Post
Any example would u like to give ?

Regards,
Rehan
Why don't you give us an example of what you are trying to do?
 
1 members found this post helpful.
Old 02-09-2013, 08:37 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,695

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by rehan21 View Post
Any example would u like to give ?
Spell out your words, please. And there are many bash scripting tutorials you can easily find...there is a link to one in my signature here. I gave you links with examples already in my first reply, and there is a sample script in post #5 that druuna provided. How many more examples would you like?
 
Old 02-09-2013, 09:10 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
Originally Posted by druuna View Post
Simple:
Code:
#!/bin/bash

wget -O /tmp/fixed.txt http://match.fixing.cn/.hidden/winners/fixed.matches.txt

grep "Kempton Park" /tmp/fixed.txt | grep "4:30"

doh!
I shoulda oughta known it!
 
  


Reply



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
[SOLVED] Bash Script - Check Argument with REGEX mrm5102 Programming 9 04-10-2012 10:07 AM
Bash Script argument disappears wahming Linux - General 4 10-26-2010 05:03 AM
Bash script: how do I select second-to-last argument in a list Robert S Linux - Software 2 11-23-2007 03:06 PM
output of one script to another as argument sefaklc Programming 9 09-03-2007 03:06 AM
BASH: rename an argument of the script sylvaticus Programming 2 05-21-2007 08:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:26 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration