LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-18-2008, 05:51 PM   #1
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
how to anwer the questions as a result of a command in the script itself?


In a script, i give the follwoing line

rm 0000*.*


When the script is excuting this line ,
the following question pops up at the time of execution and i have to answer Y or N to let the script continue executing.

rm: remove write-protected regular file `000000000000000A.dat'? y


Now i want to give Y to the question inside the program itself so that this question does not pop up at all while executing the script from start to finish..


how to do it?

thanks
 
Old 06-18-2008, 05:54 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Use the -f option to rm.
 
Old 06-18-2008, 06:05 PM   #3
Cuetzpallin
Member
 
Registered: Feb 2008
Location: Monterrey, MX
Distribution: Slackware since 3.4 and love it!!!
Posts: 162

Rep: Reputation: 31
Quote:
Originally Posted by pdklinux79 View Post
In a script, i give the follwoing line

rm 0000*.*


When the script is excuting this line ,
the following question pops up at the time of execution and i have to answer Y or N to let the script continue executing.

rm: remove write-protected regular file `000000000000000A.dat'? y


Now i want to give Y to the question inside the program itself so that this question does not pop up at all while executing the script from start to finish..


how to do it?

thanks
You can use the -f option and rm assume Y to all
 
Old 06-18-2008, 06:15 PM   #4
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Original Poster
Rep: Reputation: 15
thank you people.. U can clearly see im a newbie.. thanks for all the help thats coming my way...
 
Old 06-18-2008, 07:16 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Here is another way:
rm -i 000*.* < <(yes y)

The yes command will output "y".

Now suppose that you want to move a bunch of files but you don't want to overwrite files in the destination directory:
mv -i 000*.* dest/ < <(yes n)

This will answer "n" to the prompt protecting files in dest/ from being overwritten because they have the same name.
 
Old 06-19-2008, 12:38 AM   #6
aTxIvG4001
LQ Newbie
 
Registered: Jun 2008
Location: Japan
Distribution: AMD64.Kubuntu
Posts: 18

Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
Here is another way:
rm -i 000*.* < <(yes y)

The yes command will output "y".

Now suppose that you want to move a bunch of files but you don't want to overwrite files in the destination directory:
mv -i 000*.* dest/ < <(yes n)

This will answer "n" to the prompt protecting files in dest/ from being overwritten because they have the same name.
This is cool!
 
Old 06-19-2008, 01:15 AM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Use a pipe instead if you want to use "yes". There's no reason to create a subshell.

Code:
yes | rm -i 000*.*
 
Old 06-19-2008, 03:09 AM   #8
ischi
Member
 
Registered: Apr 2008
Location: Tübingen
Distribution: Fedora 9 (Thinkpad T60), Debian 3.1 (Server)
Posts: 51

Rep: Reputation: 15
Wow thats so cool I've been working with Linux/Unix for years now and never stubled upon this command, thanks
 
Old 06-19-2008, 03:26 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Quote:
Originally Posted by Mr. C. View Post
Use a pipe instead if you want to use "yes". There's no reason to create a subshell.

Code:
yes | rm -i 000*.*
The form <(yes y) is an example of command substition. Even if the yes command runs in a subshell, IMHO it is a more straight forward form. And looks nice to boot!

Here is an interesting form: "< <(yes :)".

Nothing like putting a smiley in a command! Although this doesn't answer yes.

Last edited by jschiwal; 06-19-2008 at 03:32 AM.
 
Old 06-19-2008, 03:51 AM   #10
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
The <() form is *not* command substitution; it is *process substitution*, and it does something undesired for your example. It passes the name of a named pipe as an argument to the rm program. Example:

Code:
rm a b <(yes)
ends up as something similar to:

Code:
rm a b /dev/fd/62
certainly not the desired result (unless you want to delete the named pipe /dev/fd/62 as well)!

To be more clear
Code:
rm a b <(yes) != yes | rm a b
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Shell script to cd into the result of Find odinsride Programming 5 10-17-2007 11:33 AM
python - getting command result Hewson Programming 1 08-01-2007 07:22 PM
BASH Command Result redhatnoob Programming 2 08-19-2004 07:25 PM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 01:11 PM
no result from running script cowardnewbie Programming 1 09-09-2001 08:26 PM


All times are GMT -5. The time now is 10:44 AM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration