Active 1 year, 7 months ago. Viewed 2k times. Improve this question. NoExpert NoExpert 2 2 silver badges 9 9 bronze badges. Is there a reason you're wanting to update your hosts file? It's not commonly used now a days. There are certain domains that I don't want my machine to connect to. Add a comment. Use grep -P instead. On running the above script as follows i. Every time i run the script it ask for password.
I dont want to enter the password manually. Has any one solved this problem??? Do you mean password prompt when you use sudo command? Skip to content.
Sign in Sign up. Instantly share code, notes, and snippets. Created Mar 7, Add a comment. Active Oldest Votes. Try echo ' Improve this answer. Candy Gumdrop Candy Gumdrop 2, 1 1 gold badge 16 16 silver badges 16 16 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Is there a difference? I think it should be a directory independent from the user and user settings. It looks like you intend this script to be used at differing privileges level e. Note that this won't present itself if you only use sudo. For ls , do not print Empty if there is no hosts blocked. The correct way is to be silent if you find no data. This will assuming some one else uses it allow them not to special case the Empty case. That is the below should suffice.
Another style point. You might want to consider avoiding the superfluous quotes. That is, use case ls rather than case 'ls'. I think the former is more often used, and clearer. Consider also that it could be used from a cron to switch at particular times of the day. You might also want to think what the behavior would be, when you add a new host when a block is already in effect.
It is considered a better practice in Unix to be silent when there is not much information to be added. Sign up to join this community.
0コメント