Minimize the amount of code in your bash scripts
A new article entry has been added:
Minimize the amount of code in your bash scripts Quote:
|
I'm sorry, but I need to say the code you presented is inefficient. You need to eliminate $( .. ), because that will invoke a new shell and usually can be solved without that (which will need less resources, run faster...)
|
Yes surely but the article is on minimizing code not making it more efficient. It's focus is on reducing the amount of code necessary to deal with input flags/parameters and configuration file creation.
I'll see if I can review the code so that it's not a bad example of bash coding ... can I edit my article ? Help me find the contents of a variable whose name is in another variable ... I know what I did is a mess but I still can't think of an alternative. |
Quote:
Code:
A=B |
Quote:
|
probably there is an edit button, but actually you can post an improved version too.
|
Quote:
But if it's not possible I guess a rewrite will be scheduled. |
Quote:
It's the plain ( list ) that invokes a subshell to run the list. Ok but still you have a point: there are some places where I can do without command substitution and I can declare som variables as integer and do without some of the ((expression)). It will be an exercise for me to write cleaner bash scripts ;) |
The $( ) or ( ) is a sub shell.
That is another process, or at least it behaves like one. An example should demonstrate this Code:
x=1 My attempt for an efficient coding Code:
get_myoptions_value () BTW nothing speaks against Code:
if [ "$OPTION" = "$SEARCH_OPTION" ] ; then echo $VALUE ; break ; fi |
To my understanding, which may be wrong, $(command) forks the command so if it's a shell it will run a subshell if it's an executable it will execute the command obviously in another process in any case.
$(command) and `command` do the same thing I just prefer the newer $(command) syntax. As I said before this not about optimizing code for performance but all about minimizing the amount of code necessary to deal with scripts with several options and configuration parameters. Although I appreciate comments regarding attempting to get petter performance I do thing that they're missing the whole point of the article. In any case a reedit or improved version is pending MYOPTIONS is an associative array you don't need to walk the whole looking for the looking for the right element. Code:
get_myoptions_value () |
for example:
Code:
eval $(echo dialog --title \"$TITLE\" --yesno \" ${STRING[*]}\" 0 0 ) && return 1 || return 0 |
Quote:
|
All times are GMT -5. The time now is 11:54 AM. |