LinuxQuestions.org
Have you heard the LinuxQuestions.org Podcast?
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
 
Thread Tools
Old 09-10-2004, 10:19 PM   #1
laikos
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1
Posts: 30
Thanked: 0
Question Shell script pipe input - bash mostly


[Log in to get rid of this advertisement]
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
laikos is offline     Reply With Quote
Old 09-11-2004, 02:47 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 1,463
Thanked: 0
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
Cedrik is offline     Reply With Quote
Old 09-11-2004, 01:55 PM   #3
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 12,877
Thanked: 232
Is this what you mean?

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

Original Poster
Hi Cedrik,
You solution is exact solution I been looking for, jschiwal, thanks for the suggestion.
laikos is offline     Reply With Quote
Old 11-09-2008, 06:14 PM   #5
kdocki
LQ Newbie
 
Registered: Nov 2008
Posts: 1
Thanked: 0
Here is something I've done...

Code:
# buffer the input data
ary=()

while read data; do
  ary=( "${ary[@]}" "$data" )
done
kdocki is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 04:46 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 04:14 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 10:59 PM
bash-script input aizkorri Programming 7 07-08-2003 07:15 AM


All times are GMT -5. The time now is 08: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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration