Timeline for sudo without sudo, implying sudo in script
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 7, 2019 at 3:50 | comment | added | Rakib Fiha | the case statement is working like a charm now, but I wanted to make a hash table because now my number of functions are increasing and did not want to write case statement for every single function one by one. For some reason case statement is worked only for the first object of the array. Thank you again. Learnt alot from this. | |
| Apr 7, 2019 at 3:45 | vote | accept | Rakib Fiha | ||
| Apr 6, 2019 at 13:03 | history | edited | Kusalananda♦ | CC BY-SA 4.0 |
added 132 characters in body
|
| Apr 6, 2019 at 9:51 | comment | added | Kusalananda♦ |
@RakibFiha Note that you don't need to do that as you can simple switch through the valid cases, and output an error when none matches. The point is that you don't use the string given to you by the user as something you can call. Instead you use that string to figure out if it's a sting that is valid. It's very much like testing the command line options (-h, -a etc.) to see whether a given option is valid or not.
|
|
| Apr 6, 2019 at 9:47 | comment | added | Rakib Fiha | Thank you very much. Now I am trying to figure out how can I check if the parameter passed exists as a function from an array as Im trying to implement your case statement. | |
| Apr 6, 2019 at 8:43 | comment | added | Kusalananda♦ |
@RakibFiha Note that you can't easily use sudo with functions (if you need to do that). See e.g. Executing a Bash Script Function with Sudo
|
|
| Apr 6, 2019 at 8:02 | history | edited | Kusalananda♦ | CC BY-SA 4.0 |
added 9 characters in body
|
| Apr 6, 2019 at 7:57 | comment | added | Rakib Fiha | Wow, this was explained so perfectly. I will implement this case statement to avoid inputting invalid commands. Also, I was feeling the same way as you about implying sudo, and giving prompt to user if run without sudo would be much better, but I think I will still try to imply sudo after I sanitize the input from user. :) | |
| Apr 6, 2019 at 7:52 | history | edited | Kusalananda♦ | CC BY-SA 4.0 |
added 36 characters in body
|
| Apr 6, 2019 at 7:38 | history | answered | Kusalananda♦ | CC BY-SA 4.0 |