LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-10-2004, 09:19 PM   #1
laikos
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1
Posts: 30

Rep: Reputation: 15
Question Shell script pipe input - bash mostly


Hi
I've been working on trying to create shell script that can accept piped data from another command.
example would be
ls -al | ./myscript.sh

#!/bin/bash
title=$1
data=$2
echo "title = $title"
echo "data = $data"
echo -e -n "\033[7s"
tput cup 0 0
echo -n $title
echo -e -n "\033[8u"
echo -n $data

So, what it suppose to do is to print the title at location 0 0 of the screen and then list the file at the current location of the cursor. The output should look somehow like below:

[ My Program ]**********************************************

drwxr-xr-x 4 nobody nobody 376 Sep 11 09:59 .
drwxrwxrwx 27 root root 1664 Sep 10 21:48 ..
-rw------- 1 root root 12288 Sep 11 09:40 .clock.sh.swp
drwx------ 8 root root 672 Sep 10 22:25 audio.o5AxVk
-rwx--x--x 1 root root 1273 Sep 10 21:55 blink.sh
-rwx--x--x 1 root root 923 Sep 10 21:50 clock.sh
-rwxr-xr-x 1 root root 7881 Sep 10 23:07 leave
-rw------- 1 root root 691 Sep 10 23:07 leave.c
-rwx--x--x 1 root root 740 Sep 10 22:01 math.sh
-rwxr-xr-x 1 root root 155 Sep 11 09:59 my.sh
-rwx--x--x 1 root root 3301 Sep 10 21:58 show.sh
 
Old 09-11-2004, 01:47 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
I don't know what you call $title and $data but try this :

Code:
#!/bin/bash

while read data; do
    echo "data = $data"
done
ls -al | ./myscript.sh
 
1 members found this post helpful.
Old 09-11-2004, 12:55 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Is this what you mean?

Code:
#!/bin/bash
tput cup 0 0
echo "[ my program ] *************"
cat -
 
Old 09-12-2004, 12:10 AM   #4
laikos
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1
Posts: 30

Original Poster
Rep: Reputation: 15
Hi Cedrik,
You solution is exact solution I been looking for, jschiwal, thanks for the suggestion.
 
Old 11-09-2008, 05:14 PM   #5
kdocki
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
Here is something I've done...

Code:
# buffer the input data
ary=()

while read data; do
  ary=( "${ary[@]}" "$data" )
done
 
  


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
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 03:46 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

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

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

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