Skip to main content
Added the "yes" tag - originally not available, wanted by the OP which could not create it. Improved formatting of code
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

2nd EDIT: Another example: I have an alias to list AWS SNS topics in a region like:

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn "

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn " 

Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

2nd EDIT: Another example: I have an alias to list AWS SNS topics in a region like:

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn "

Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

2nd EDIT: Another example: I have an alias to list AWS SNS topics in a region like:

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn " 

Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?

added 783 characters in body
Source Link
Gabriel
  • 139
  • 1
  • 4

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATEUPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

2nd EDIT: Another example: I have an alias to list AWS SNS topics in a region like:

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn "

Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

2nd EDIT: Another example: I have an alias to list AWS SNS topics in a region like:

alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn "

Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?

Made clear that this question is not about `rm`, but about how to use `yes` with `xargs -p`
Source Link
Gabriel
  • 139
  • 1
  • 4

How to use yes`yes` with xargs`xargs -pp`?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

How to use yes with xargs -p?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

How to use `yes` with `xargs -p`?

Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag?

I tried yes n | (ls | xargs -n1 -p rm) but didn't work.

P.S. I tried to add the yes tag, but didn't have enough rep.

UPDATE: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it.

Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally.

Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't.

Source Link
Gabriel
  • 139
  • 1
  • 4
Loading