Condition local or remote server command

Hello,

Can you help me ?
$7 fits to remote server.
I can launch the script from local or remote server.
I would like my_script.sh to choose local or remote command depending the variable $7.
Is the function f1 right or wrong ? In this moment, i can't test it.
Thanks in advance.

I create the input file

vi my_inputfile
# comment 1
# comment 2
$1 $2 $3 $4 $5 $6 $7
./my_script my_inputfile
vi my_script
#!/bin/bash
# set -vx
f1()    {
          server=$(hostname -s)
          if [ $server = $6 ]; then
          echo $1 $2 $3 $4 $5 $6   
          else
          ssh -n $6 'echo $1 $2 $3 $4 $5 $6'                                   
        } 
case $# in
        0)      echo -e "# comment1\n# comment2" > list_file    
                read -p "Please fill in this list_file: "      
                echo $REPLY                                     
                ;;
        1)     if [ ! -f "$1" ] 
               then  > $1 && echo -e "# comment1\n# comment2" > $1
               read -p "Please fill in "$1": "
               echo $REPLY 
               else 
                   if [ -f "$1" -a $(grep -v '^#' "$1" | wc -l ) -ne 0 ]                             
                   then
                   grep -v '^#' "$1" |
                        while read arg1 arg2 arg3 arg4 arg5 arg6 arg7
                                do f1 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
                                done  
                   else 
                   read -p "Please fill in $1 : "
                   echo $REPLY
                   fi 
               fi
               ;;  
        4)      echo -e "# comment1\n# comment2" > list_file    
                echo $1 $2 $3 $4 >> list_file                   
                ;;
        5)      echo -e "# comment1\n# comment2" > $1           
                f1 $2 $3 $4 $5 $6 >> "$1"                   
                ;;
        6)      echo -e "# comment1\n# comment2" > $1           
                f1 $2 $3 $4 $5 $6 $7 >> "$1"                   
                ;;
        *)      echo "error msg"; exit
esac

Until you test it , difficult to find if this is having any issue.

Will try to run it in a script and see if that helps. I may will comeback to you later.

There was a problem when the file my_inputfile has more than one line. There was a break after the first line. I had to add -n after ssh.
Now, it's OK

I want to modify the beginning of the script like that.
But it doesn't work. Have you an idea ?

#!/bin/bash
# set -vx
f1()    {
          server=$(hostname -s)
          if [ "$server" == "$6" ]; then
                 cde=""         
           else
                cde=$(ssh $6)
           $cde echo $1 $2 $3 $4 $5 $6
        fi
        }

Try to eval that line, but be aware that the usage of eval is highly discouraged due to security reasons.