Issues with setting Aliases


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues with setting Aliases
# 15  
Old 02-08-2016
I have final question after learning how flags work.

i m on Linux fedori 2.6.35.14 GNU/Linux

So, i can confirm that on my OS that which ever flag come later takes precedence. So

rm -fi works and asks for confirmation
rm -if does not work and force deletes the file.

Now when i set alias rm='rm -i' and then try rm -f it does not ask for confirmation and force deletes the file; meaning it populates the final command as rm -if

Do you know of any trick by which i can force interactive -i flag to kick in by setting it in the alias ? Somehow please ?

Last edited by mohtashims; 02-08-2016 at 04:33 PM..
# 16  
Old 02-08-2016
Quote:
Originally Posted by mohtashims
I have final question after learning how flags work.

i m on Linux fedori 2.6.35.14 GNU/Linux

So, i can confirm that on my OS that which ever flag come later takes precedence. So

rm -fi works and asks for confirmation
rm -if does not work and force deletes the file.

Now when i set alias rm='rm -i' and then try rm -f it does not ask for confirmation and force deletes the file; meaning it populates the final command as rm -if

Do you know of any trick by which i can force interactive -i flag to kick in by setting it in the alias ? Somehow please ?
No. An alias cannot override what follows it on the command line.

You could write a replacement script for rm and install it in your PATH before the standard rm and have it examine its arguments and insert a -i before the first operand and then invoke the standard rm utility. But, if someone using your alias explicitly asks for -f to be used, why do you want to override that???
# 17  
Old 02-08-2016
Even if rm -f wouldn't inhibit the -i - \rm would. It bypasses the alias.
# 18  
Old 02-08-2016
Quote:
Originally Posted by MadeInGermany
Even if rm -f wouldn't inhibit the -i - \rm would. It bypasses the alias.
Sorry, i did not get what you are trying to say here.

My question is that irrespective to the order of -i or -f flags the rm should always prefer -i and ask for confirmation. Can i somehow enforce this to happen ? Yes or No ? If Yes, How ?

Last edited by mohtashims; 02-08-2016 at 11:54 PM..
# 19  
Old 02-09-2016
No. And, there is no logical reason to want to do so.

Why do you think it is important to override a user not wanting the output produced by -i when that user explicitly asks for the behavior afforded by -f?

If this is for an alias you are defining for your own use, why does it matter? Just don't type -f when you use the alias if you don't want to use -f! If this is an alias you are creating for others to use, DO NOT ATTEMPT to thwart a user's attempt to get the behavior they need for the job they are doing.
# 20  
Old 02-09-2016
Hammer & Screwdriver

Quote:
Originally Posted by Don Cragun
No. And, there is no logical reason to want to do so.

Why do you think it is important to override a user not wanting the output produced by -i when that user explicitly asks for the behavior afforded by -f?

If this is for an alias you are defining for your own use, why does it matter? Just don't type -f when you use the alias if you don't want to use -f! If this is an alias you are creating for others to use, DO NOT ATTEMPT to thwart a user's attempt to get the behavior they need for the job they are doing.
@Cragun: We have naive users who are given access to our servers. They do not understand the significance of -f option and due to overlook they may specify a folder instead of a file becoz they overlooked the space charecter in the path to the file making it a folder path.

rm -irf /tmp/hello /output/bob.txt

This will accidentally delete the folder "hello" instead of the file "bob.txt" as they copy paste these path from word documents or emails.

So if i can impose the -i option for others as we use the same id they will be prompted and thus they can correct their mistake rather than the -f option doing the damage.

Your suggestions please... to my concern ?

Also, i was wondering where the same behavior of a later flag over riding the behavior of the previous flag could be tested.

I tried grep "Sunday" -wi hello.txt and grep "Sunday" -iw hello.txt but i get the same output where as grep "Sunday" -w hello.txt and grep "Sunday" -i hello.txt yields different results.

Can you tell me other commands and the flags that override each others behavior like the -i and -f flag over rides each other in case of rm command.

Last edited by mohtashims; 02-09-2016 at 12:46 AM..
# 21  
Old 02-09-2016
Quote:
Originally Posted by mohtashims
@Cragun: We have naive users who are given access to our servers. They do not understand the significance of -f option and due to overlook they may specify a folder instead of a file becoz they overlooked the space charecter in the path to the file making it a folder path.
First off: if you do not want a user to delete a file set the ownerships and other rights of this file accordingly. This is what they are for.

Second: if you do not want users to execute a certain command flag the executable accordingly by taking away the execute-rights for "others". This is what this device is for.

Third and foremost: users may be technically less savvy but they aren't idiots. They might shoot themselves into the foot sometimes but not because they are masochists - they simply didn't know better. In fact they have some work to do (this is why all the servers and their maintenance staff were brought in in first place) and letting the system second-guess what they want to do is usually a bad idea.

In fact there is such a system: Microsoft Windows. Guess, why 99% of the important servers are NOT running an OS with the design philosophy of when the user says he wants A i suppose what he really wants is B therefore i will do C claiming that i did D instead because the moron using me wouldn't know the difference between A,B,C and D anyway. This is not only an insulting attitude towards users it is also putting obstacles into getting work done because you have to "third-guess" what the OS might "second-guess" to get done what you really want: instead of doing A we have to pretend we want D so that the OS thinks what we really want is C and therefore claims doing B while in fact doing A.

This is the mental gymnastics i can do without. Instead of having to anticipate the anticipation of the reinterpretation of my real motives just to get what i want i'd rather do my work using the computer as an (unthinking but efficient) tool and keep the thinking to myself. No, i don't think i am in a minority.

I hope this helps.

bakunin

/PS: if you try to make an intelligent system "idiot-resistant" chances are you end up with a very idiotic system which is resistant against any intelligent use one could make of it. Applying this to your case it means: if a user uses "-f" to override "-i" he might - as well as being ignorant - have a certain reason for that. By trying to override this you do not make the system one iota more secure but a lot less usable.

If someone would be dumb enough to voluntary override the default "-i" switch with the "-f" switch to have a wrong file deleted - don't you think this same person would also be dumb enough to answer an enforced question of "do you really want to delete ...." with "yes"?. So maybe the complete removal of "rm" would help? Yes and no: the user might not be able to delete the file but he still can shorten it to 0 bytes. So take away vi, sed, awk and all the other possibly file-changing commands - AND FINALLY THE SHELL itself, because one could simply redirect into the file, yes? You have finally gotten your wish: the system is completely secure - and completely unusable too! Congrats!

Last edited by bakunin; 02-09-2016 at 03:56 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Proxy Server

Samba on AIX, issues setting read-only flag on files?

Hello, I am having issues setting the "read-only" flag via Windows Explorer on my AIX Samba share... I have on my AIX 7.1 system installed Samba 3.6.24 and configured, joined to our Windows domain successfully. The samba binaries I got from perzl.org/aix In my smb.conf I have... ... (1 Reply)
Discussion started by: c3rb3rus
1 Replies

2. Solaris

Is there a difference between setting a user as nologin and setting it as a role?

Trying to figure out the best method of security for oracle user accounts. In Solaris 10 they are set as regular users but have nologin set forcing the dev's to login as themselves and then su to the oracle users. In Solaris11 we have the option of making it a role because RBAC is enabled but... (1 Reply)
Discussion started by: os2mac
1 Replies

3. UNIX for Advanced & Expert Users

Issues in setting up remote syslogging

Hello, I am using Ubuntu Linux and having problems in setting up remote syslogging. Appreciate your help on this. On the server unix host, I have made following changes. uncommented following lines in /etc/rsyslog.conf $ModLoad imudp $UDPServerRun 514 Now i am trying to run rsyslog in... (0 Replies)
Discussion started by: ravi.videla
0 Replies

4. Solaris

Help with beginner issues setting up ZFS??

Hi, I'm new to Solaris 11. The goal is to set up a ZFS raid-Z2 NAS. These are the instructions I've been trying to follow, with no luck: "Setting Up an OpenSolaris NAS Box: Father-Son Bonding" (not allowed to post URL) Issues: 1) Root access is evidently required but I don't... (8 Replies)
Discussion started by: lakedude
8 Replies

5. UNIX for Dummies Questions & Answers

Setting aliases

How come if I set an alias as such: alias dt 'date "+%Y-%m-%d %H:%M:%S"' it will work as intended, ie the command 'dt' does prompt the date and time, but not when invoked through a script as such: #!/bin/sh alias dt 'date "+%Y-%m-%d %H:%M:%S"' The OS is FreeBSD 7.1. Thanks in advance (4 Replies)
Discussion started by: figaro
4 Replies

6. Shell Programming and Scripting

etc aliases

Hello: i have several server with own etc aliases. right now i want to combine it all into a general etc aliases in a new freebsd server. cause it consist hundred thousand of record user inside how to make a shell script to combine it or configure it. all etc aliases record example: ... (0 Replies)
Discussion started by: peterLfs
0 Replies

7. UNIX for Dummies Questions & Answers

aliases

Is there a way to view what aliases are running on a given session? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. Programming

aliases

Hi. I have a C program that is using the **environ pointer and I am trying to set up aliases for a system("/bin/ksh") call. This works for other environment variables but not for the aliases. Does anyone know if this can be done? Thanks ahead of time. (1 Reply)
Discussion started by: mluey61
1 Replies
Login or Register to Ask a Question