Visit Our UNIX and Linux User Community


how do I list my values one per line instead of across it?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do I list my values one per line instead of across it?
# 1  
Old 08-27-2009
how do I list my values one per line instead of across it?

I want to list my vars in a script so they look like
Code:
while read IN
var1
var2
var3
var4
do
echo $IN
done

Then in the same script have them read and processed.

the closest I can get is as follows but this is obviously wrong.
NOTE I want a list not all the entries on one line, that would be too easy.

Code:
while read IN; hello; you; other; test; ok; do echo $IN; done

Perhaps I should use a EOF tag?

hope this makes sense. Smilie

Thanks

---------- Post updated at 04:42 PM ---------- Previous update was at 04:19 PM ----------

By George I did it on my own.

Code:
LIST=`cat << EOF
ls
echo
udevinfo
fdisk
xdisk
dmidecode
lsusb
EOF`
echo $LIST
read
for i in $LIST
do
if which $i &> /dev/null
then
echo "There it is $i"
else
echo "$i It's not there"
fi

done

I think this is the right way any other suggestions are welcome though, I'd like to make it look cleaner.
# 2  
Old 08-27-2009
i suggest put all the commands to a parameter file and read through it instead of writing it in a script. if in case you need to add more you can do so in the parameter file instead.
# 3  
Old 08-27-2009
A couple of variations...

Code:
(cat <<EOF
var1
var2
var3
var4
EOF
) | awk '{print $0}'

or if you had your list in a file like suggested above...

Code:
awk '{print $0}' yourfile

# 4  
Old 08-27-2009
Quote:
Originally Posted by pobman
By George I did it on my own.

Code:
LIST=`cat << EOF
ls
echo
udevinfo
fdisk
xdisk
dmidecode
lsusb
EOF`


Why use cat?

What's wrong with:

Code:
LIST="ls
echo
udevinfo
fdisk
xdisk
dmidecode
lsusb
"

?
Quote:
Code:
echo $LIST
read
for i in $LIST
do
if which $i &> /dev/null


Don't use which. It is non-standard, and it often doesn't work. Use type instead:

Code:
type $LIST

Quote:
then
echo "There it is $i"
else
echo "$i It's not there"
fi

done[/CODE]

I think this is the right way any other suggestions are welcome though, I'd like to make it look cleaner.
# 5  
Old 09-02-2009
Thanks for your suggestions, I always find it interesting to see other peoples variations. (there are many ways to skin a cat as they say.)

I tried to use the type command but unfortunately it was not installed on all the servers the script was to run on, so I used a simple if test to see if the executable file existed instead.

Smilie
# 6  
Old 09-02-2009
Quote:
Originally Posted by pobman
I tried to use the type command but unfortunately it was not installed on all the servers the script was to run on, so I used a simple if test to see if the executable file existed instead.

type doesn't have to be installed; it is part of every Bourne-type shell of the last 20, if not 30, years.

If you don't have it, you must be using csh or tcsh. Those are non-standard shells that are not recommended for scripting.

Previous Thread | Next Thread
Test Your Knowledge in Computers #174
Difficulty: Medium
The Apache 2 'Fancy indexing' directive shows the files plus the date the file was last modified, the size and the user who originally created the files.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

2. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

3. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

4. Shell Programming and Scripting

how to use loops to take the values line by line

Hi am using aix ... I have tried so far but am getting unknown test operator error for example i have three files in one dir ... A2008 A2408 A2808 final output results should be A0108 is missing --- A1908 is missing A2108 is missing ..... #! /bin/ksh i=`ls A* |cut -c2-3` j=`date... (3 Replies)
Discussion started by: Venkatesh1
3 Replies

5. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

6. Shell Programming and Scripting

grep a list of values

Hi everybody! :) :D :D :) it's great to be here since this is my first post. touch /base/oracle/FRA/XMUT00/RMAN_FLAG touch /base/oracle/FRA/XRLL00/RMAN_FLAG find directory name containing RMAN_FLAG : $ find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u... (3 Replies)
Discussion started by: jolan_louve
3 Replies

7. Shell Programming and Scripting

Comma Seperated List of Values

Hi, I have a comma seperated list of values: export list="red,blue,white,yellow" Given a value in a variable "look", i want to check whether the value is available in the above list. But the result should be based on exact string match and not part of the string. I am using following... (9 Replies)
Discussion started by: brap45
9 Replies

8. Shell Programming and Scripting

Search list of values

I have a file which contains a list of search values $cat my.txt FTIP002671604 FTIP002702940 FTIP002703183 FTIP002414805 And lots of such search values. I have to search these valus in the current directory. Can we do this one command wihtout writing a script. Regards, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies

Featured Tech Videos