-1

Need somme help with shell scripting plz I tried to uncomment fonction by pair in a script, let me explain : I have a text file with commented lines, with a shell script a created a fonction list and uncomment the line with the fonctions we choose. But some of these fonctions have a dependencies of another fonction For example :

  1. text file ` #!/bin/sh ###====================================================================

    --- Choose fonctions

    ###==================================================================== ###execution des fonctions de calnuit sans modifier le standard ###fonction 1### #some fonction 1 ###fonction 2### #some fonction 2 ###fonction 2### #some fonction 2 ###fonction 3### #some fonction 3 ###fonction 4### #some fonction 4 ###fonction 5### #some fonction 5 ###fonction 6### #some fonction 6 `

  2. Fonction list

  1. fonction 3) fonction 5) fonction 7) fonction
  2. fonction 4) fonction 6) fonction 8) Finished

choose fonction to activate:

So actually i have to choose all the fonction i want to uncomment but somme of these depends of each other For example fonction 1 stop service1 and fonction 2 start service1 So i want if i choose fonction 1 automaticly it uncomment also fonction 2

Here the actual code

    ```
    #!/bin/bash
    PS3=$'\n\nchoose fonction to activate: '
    options=$(grep -v '###' fonction_list.txt | awk '{ print $2}')
    # Variable to store fonction choice
    choices=()
    
    select choice in $options Finished
    do
      # Stop choosing on this option
      [[ $choice = Finished ]] && break
      # Append the choice to the array
      choices+=( "$choice" )
      echo "$choice, Quel(s) autre(s) fonction(s) pour BATCH?"
    done
    
    # Construction du calnuit Batch
    printf "Activation des fonctions de calnuit Batch: "
    for choice in "${choices[@]}"
    do
      sed -i '/pattern '$choice'/s/^#*//g' fonction_list.txt
      cp -f fonction_list.txt fonction_list.sh
      chmod +x fonction_list.sh
    done
    ```

Thanks you for your help

  • 1
    You did not ask any questions. If it is concerning the logic, we could not really help you without having the functions and their logic. Also, commenting and uncommenting inside a file is a dirty practice. – pgossa Aug 04 '23 at 07:58
  • 1
    [Why is "Can someone help me?" not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – ray Aug 04 '23 at 08:01
  • The script with the function calls should be using conditionals to execute them (i.e. checking the values of configuration variables which enable or disable functions). Not commenting or uncommenting. That's fine for debugging, not as part of the application logic! The conditional checks can handle the dependencies, if they are carefully written. You can have some function which sets dependent variables. E.g. if service X needs service Y, the function would do `[ "$service_X_enabled" ] && service_Y_enabled=y`. – Kaz Aug 04 '23 at 23:05
  • Hello everyone problem solved i apply that is explain in this topic https://stackoverflow.com/questions/3826425/how-to-represent-multiple-conditions-in-a-shell-if-statement – Kain Taozia Aug 31 '23 at 15:15

0 Answers0