Skip to content

Instantly share code, notes, and snippets.

@zfhxi
Last active March 15, 2023 16:19
Show Gist options
  • Save zfhxi/79658216f17e3fc43b6bc6cbdcceb56e to your computer and use it in GitHub Desktop.
Save zfhxi/79658216f17e3fc43b6bc6cbdcceb56e to your computer and use it in GitHub Desktop.

Revisions

  1. zfhxi revised this gist Mar 15, 2023. 1 changed file with 7 additions and 14 deletions.
    21 changes: 7 additions & 14 deletions modify_interpreter.sh
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,10 @@
    #!/bin/bash
    current_interpreter=/opt/cszmxApps/Miniconda3/envs/tfan/bin/python
    target_interpreter_dir=/home/denglong/.miniconda3/envs/tfan/bin
    target_interpreter=$(realpath "$target_interpreter_dir""/python")

    echo "current_interpreter: $current_interpreter"
    echo "target_interpreter: $target_interpreter"
    for bin_file in $target_interpreter_dir/*
    BIN_PATH=$1/bin
    PYTHON_INTERPRETER="#!$(realpath $BIN_PATH/python)"
    for file in $BIN_PATH/*
    do
    if test -f $bin_file
    then
    # bin_file_list=(${bin_file_list[*]} $bin_file)
    sed "s!$current_interpreter[\d\.]*!$target_interpreter!g" $bin_file |head -n 1
    # sed -i "s!$current_interpreter[\d\.]*!$target_interpreter!g" $bin_file
    fi
    done
    # echo ${bin_file_list[@]}
    if [[ $(file -b "$file") == *"Python script"* ]];then
    sed -i "1s|.*|$PYTHON_INTERPRETER|g" $file
    fi
    done
  2. zfhxi created this gist Sep 25, 2021.
    17 changes: 17 additions & 0 deletions modify_interpreter.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash
    current_interpreter=/opt/cszmxApps/Miniconda3/envs/tfan/bin/python
    target_interpreter_dir=/home/denglong/.miniconda3/envs/tfan/bin
    target_interpreter=$(realpath "$target_interpreter_dir""/python")

    echo "current_interpreter: $current_interpreter"
    echo "target_interpreter: $target_interpreter"
    for bin_file in $target_interpreter_dir/*
    do
    if test -f $bin_file
    then
    # bin_file_list=(${bin_file_list[*]} $bin_file)
    sed "s!$current_interpreter[\d\.]*!$target_interpreter!g" $bin_file |head -n 1
    # sed -i "s!$current_interpreter[\d\.]*!$target_interpreter!g" $bin_file
    fi
    done
    # echo ${bin_file_list[@]}