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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
gcd.sh script doesn't work... kantze Shell Programming and Scripting 1 01-17-2008 09:46 PM
Modify Perl script to work with txt - Permissions script joangopan Shell Programming and Scripting 1 09-12-2007 11:38 PM
My script does not work - could you pls help? BearCheese Shell Programming and Scripting 1 06-29-2007 05:12 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM
sed script. How does it work? billy5 Shell Programming and Scripting 2 09-02-2005 04:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2008
llsmr777 llsmr777 is offline
Registered User
  
 

Join Date: May 2007
Posts: 58
Help can't get script to work how I need it to...

Hi thank you for anyone who responds.

Here is my script:
Code:
for i in `ls -1 | grep $1 | grep  $2`
do
x=`echo $i | sed 's/\.Sent/\.Done/g'`
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.

Thank you!!

Last edited by radoulov; 10-13-2008 at 03:07 PM.. Reason: added code tags
  #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.
  #3 (permalink)  
Old 10-13-2008
llsmr777 llsmr777 is offline
Registered User
  
 

Join Date: May 2007
Posts: 58
Thank you for your reply.

I thought my case statement was outside the loop?
  #4 (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
I thought my case statement was outside the loop?

The loop is everything between do and done. That's where you are asking.
  #5 (permalink)  
Old 10-13-2008
llsmr777 llsmr777 is offline
Registered User
  
 

Join Date: May 2007
Posts: 58
Ok so I changed it but after it asks me it only moved one file?
Should I not be using a case statement to perform the move?
I am using it to ask the user if the list is correct.

I thought that inside the case statement I should put what shoudl be carried out if the user says no.
Sounds like maybe I shouldn't be using case or put that somewhere else in the script?

I've very new so please bear with me. Thank you!

Last edited by llsmr777; 10-13-2008 at 03:36 PM..
  #6 (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
Ok so I changed it but after it asks me it only moved one file?

What did you change it to?
Quote:
Should I not be using a case statement to perform the move?

A case statement cannot move anything. You use mv to do the move.
Quote:
I am using it to ask the user if the list is correct.

How are you using it? We're not mind readers.
Quote:
I thought that inside the case statement I should put what shoudl be carried out if the user says no.

...and what should be carried out when the use says yes.
Quote:
Sounds like maybe I shouldn't be using case

Yes, you should use case.
Quote:
or put that somewhere else in the script?

Isn't that what I suggested?
  #7 (permalink)  
Old 10-13-2008
llsmr777 llsmr777 is offline
Registered User
  
 

Join Date: May 2007
Posts: 58
Oh I'm sorry. I'm obviously clueless I know that!

here is my code

Code:
for i in `ls -1 | grep $1 | grep  $2`
do
x=`echo $i | sed 's/\.Sent/\.Done/g'`
echo mv $i DONE/$x
done
echo "Is this OK?"
read user_response

case $user_response in

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

esac

Code:
for i in `ls -1 | grep $1 | grep  $2`
do
x=`echo $i | sed 's/\.Sent/\.Done/g'`
echo mv $i DONE/$x
done
Here i am compliing my list that I want to rename from .Sent to .Done
And then outputing it to the screen

Code:
echo "Is this OK?"
read user_response
Here I ask if what outputed was what the user wants to move


Code:
case $user_response in

"y"|"Y")

        for i in `ls -1 | grep $1 | grep  $2`
        do
        x=`echo $i | sed 's/\.Sent/\.Done/g'`
        mv $i DONE/$x;;
*)
        echo "No changes made ...";;

esac
Here I want the files to be moved from .Sent to .Done and then if the user says Y
and to print to screen "No changes made" if the user says no

When I run the script it lists all the files
then asks me if it's ok
when I hit Y
And I do a listing only 1 of the files listed were moved not all.

Thanks again.

Last edited by llsmr777; 10-13-2008 at 04:47 PM..
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 06:12 PM.


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