Bad performance bash, changing display brightness I have a script that changes the display brightness using xrandr. It is my first bash script. I mainly had a lot of trouble with dealing with the floating point values. I think that is one of the main reasons the performance is bad.

  1 #!/bin/bash                                                                                      
  2 # increase/decrease display brightness of xrandr of both displays                                
  3 # use:                                                                                           
  4 # $ ./change_brightness [up/down (0/1)]                                                          
  5                                                                                                  
  6 export current_brightness=$(xrandr --verbose | awk '/Brightness/ { print $2; exit }')            
  7                                                                                                  
  8 export increase=$1                                                                               
  9 export new_brightness=$current_brightness                                                        
 10                                                                                                  
 11 if [ "$increase" = "1" ]; then                                                                   
 12     if [ $current_brightness != "1.0" ]; then                                                    
 13         new_brightness="$current_brightness + 0.2"                                               
 14     fi                                                                                           
 15 elif [ "$increase" = "0" ]; then                                                                 
 16     if [ $current_brightness != "0.20" ]; then                                                   
 17         new_brightness="$current_brightness - 0.2"                                               
 18     fi                                                                                           
 19 fi                                                                                               
 20                                                                                                  
 21 new_brightness=$(bc &lt;&lt;&lt; "$new_brightness")                                                       
 22                                                                                                  
 23 xrandr --output eDP-1-1 --brightness $new_brightness                                             
 24 xrandr --output DP-0 --brightness $new_brightness 


The performance isn't terrible, but any improvements would be highly appreciated. Also the improvements that have nothing to do with performance.
I'm confused about your goal for this question:


performance is bad
performance isn't terrible
improvements would be appreciated
improvements have nothing to do with performance.


Nevertheless, code review notes:


you don't have to export every variable, only the ones that are needed by processes you spawn from this script.
validate inputs: why do anything if the input is neither "0" nor "1"?


Here's my take:

#!/bin/bash                                                                                      
# increase/decrease display brightness of xrandr of both displays                                
# use:                                                                                           
# $ ./change_brightness [up/down (0/1)]                                                          

current_brightness=$(xrandr --verbose | awk '/Brightness/ { print $2; exit }')            
case $1 in
    0) direction=-1;;
    1) direction=1;;
    *) echo "some error message"; exit 1;;
esac

export current_brightness direction
new_brightness=$( perl -E '
    use List::Util qw( min max );
    say max(0, min($ENV{current_brightness} + $ENV{direction} * 0.2, 1.0));
')

xrandr --output eDP-1-1 --brightness $new_brightness                                             
xrandr --output DP-0 --brightness $new_brightness