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 > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by llsmr777 View Post
Hi thank you for anyone who responds.

Here is my script:

Please enclose code in [code] tags. (Edit your original post.)
Quote:
Code:
for i in `ls -1 | grep $1 | grep  $2`

You don't need -1 when the output is not going to a terminal.

You don't need two instances of grep; use grep -e "$1" -e "$2".

You probably don't need ls, either, and it will break you script if any filenames contain spaces.

If you are trying to get files with a certain pattern, use wildcards, e.g.:

Code:
for i in *$1*$2*
Quote:
Code:
do
x=`echo $i | sed 's/\.Sent/\.Done/g'`

You don't need sed:

x=${i%%.Sent*}.Done${i#*.Sent}
Quote:
Code:
echo mv $i DONE/$x
echo "Is this OK?"
read user_response

case $user_response in

"y"|"Y")
        mv $i DONE/$x
        echo mv $i DONE/$x;;
*)
        echo "No changes made ...";;

esac

done
The list it grabs is more than one file.
When i run this it asks me if "Is this OK?" for each file. I want it to just spit out the list then ask me, if I say yes, then i want it to move all the files it lists.

If you don't want to be asked for every file, don't put the question inside the loop. Build a list and present that outside the loop.