The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read is not pausing to read davegerdt Shell Programming and Scripting 3 04-07-2008 10:20 AM
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 03:02 PM
Cannot read in variable using read on first try normie UNIX for Advanced & Expert Users 1 10-05-2005 01:42 AM
read line and read next ariuscy UNIX for Dummies Questions & Answers 7 09-21-2005 07:04 AM
read() Deepa IP Networking 1 06-07-2002 08:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-28-2006
fiol73 fiol73 is offline
Banned
  
 

Join Date: Oct 2006
Posts: 10
about READ...please help!

hi guys i have a question:

i am creating an interactive programme and i need some help on the READ command. let's say that i use the echo command and ask something to my user in the form:

echo 'Please, insert filenames: \c'

then i read his/her answer with:

read answer

i need to test the answer given to see, for example, if the user has really chosen files and not directories for example so i use:

if [[ -d $answer ]]; then
echo 'Attention: you have selected a directory!'
fi

now my problem is this: if the user, instead of just one file, writes 2 or more files?
i know i can write:

read answer1 answer2 etc.

but then it becomes too difficult to check all variables in the IF STATEMENT...and also...what if the user uses more variables than those i have specified? too complicated...

any suggestion on how to include all the possible filenames the user could specify in just one variable to check? (a bit like $@ instead of "$1" "$2" etc.)

hope my question is clear...

thanks.
  #2 (permalink)  
Old 12-28-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Try this:
Code:
#!/bin/ksh
echo 'Please, insert filenames: \c'
read filenames
filelist=""
for file in $filenames; do
        if [ -d $file ]; then
                echo "Oops, $file is a directory! Leaving that out of the final list"
        elif [ -f $file ]; then
                echo "Adding $file to the list"
                filelist="$filelist $file"
        else
                echo "$file is something I can't handle"
        fi
done
echo "Final list: $filelist"
-Edit
Oops, I missed a space there...
-/Edit

Last edited by blowtorch; 12-28-2006 at 09:40 PM.. Reason: missed a space
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0