LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Default answer (https://www.linuxquestions.org/questions/linux-newbie-8/default-answer-4175510712/)

battles 07-10-2014 02:06 PM

Default answer
 
I have this alias:

alias rm='rm -i'

and I would like for it to accept y upon just hitting enter.

Thanks.

szboardstretcher 07-10-2014 02:10 PM

You want it to default to 'y'? You'll have to change the code and recompile it then.

battles 07-10-2014 02:13 PM

Thanks. I have seen programs ask question during installs and I was under the false impression that there was some way of doing this.

szboardstretcher 07-10-2014 02:39 PM

Well,.. if you dont want to press enter everytime, but want to auto-yes it you can always pipe an echo to it:

Code:

echo y|rm -i whatever
or use yes

Code:

yes | rm -i whatever
But having it default to yes so you can press enter isn't possible AFAIK.

joe_2000 07-11-2014 06:42 PM

You could put a small script into your bin directory that does what you want. Then point your alias to the script.
The script could look similar to this:
Code:

#!/bin/bash
for i in $*; do 
        read -r -p "Delete $i? [Y/n] " userinput
        case $userinput in
            [nN][oO]|[nN])
                echo "Not deleted"
                ;; 
            *) 
                rm -f $i              # Add the -r flag here if you also want to be able to delete directories
                echo "Deleted"
                ;; 
        esac
done



All times are GMT -5. The time now is 01:18 PM.