diff --git a/miscellaneous/README.dm b/miscellaneous/README.dm index cfb53e3..8a04d95 100644 --- a/miscellaneous/README.dm +++ b/miscellaneous/README.dm @@ -4,4 +4,4 @@ Example to use insert variable: . <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/insert_variable.sh) -n USERNAME -v "YOUR_NAME" Speed test: -. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/spped_test.sh) "df" \ No newline at end of file +. <(wget -qO- http://astrader.net:3006/sem/Utils/raw/branch/main/miscellaneous/speed_test.sh) "df" \ No newline at end of file diff --git a/miscellaneous/insert_variable.sh b/miscellaneous/insert_variable.sh index 1d8e9f1..f7b8500 100644 --- a/miscellaneous/insert_variable.sh +++ b/miscellaneous/insert_variable.sh @@ -74,7 +74,8 @@ printf_n(){ printf "$1\n" "${@:2}"; } # Actions #touch $HOME/.bash_profile - if [ -f $HOME/.bash_profile ]; + FILE_BASH=$HOME/.bash_profile + if [ -f FILE_BASH ]; then echo -e "${C_LGn}File bash_profile is exist${RES}" else @@ -82,31 +83,32 @@ printf_n(){ printf "$1\n" "${@:2}"; } then echo -e "${C_LGn}Make necessary link to file bash_profile${RES}" ln -s $HOME/.profile $HOME/.bash_profile + FILE_BASH=$HOME/.profile else echo "создаем файл bash_profle" touch $HOME/.bash_profile fi fi -. $HOME/.bash_profile +. $FILE_BASH if [ ! -n "$name" ]; then printf_n "${C_R}You didn't specify a name via${RES} -n ${C_R}option!${RES}" return 1 2>/dev/null; exit 1 fi if [ "$delete_type" != "none" ]; then if [ "$delete_type" = "delete" ]; then - sed -i "0,/ ${name}=/{/ ${name}=/d;}" $HOME/.bash_profile + sed -i "0,/ ${name}=/{/ ${name}=/d;}" $FILE_BASH elif [ "$delete_type" = "delete_all" ]; then - sed -i "/ ${name}=/d" $HOME/.bash_profile + sed -i "/ ${name}=/d" $FILE_BASH fi unset "$name" unalias "$name" 2>/dev/null else if [ -n "$rename" ]; then - sed -i "s%${rename}%${name}%" $HOME/.bash_profile + sed -i "s%${rename}%${name}%" $FILE_BASH unset "$rename" unalias "$rename" 2>/dev/null if [ ! -n "$value" ]; then - . $HOME/.bash_profile + . $FILE_BASH return 0 2>/dev/null; exit 0 fi fi @@ -114,15 +116,15 @@ else printf "${C_LGn}Enter the value:${RES} " read -r value fi - if ! cat $HOME/.bash_profile | grep -q " ${name}="; then - echo "${type} ${name}=\"${value}\"" >> $HOME/.bash_profile - elif ! cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""; then - sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile + if ! cat $FILE_BASH | grep -q " ${name}="; then + echo "${type} ${name}=\"${value}\"" >> $FILE_BASH + elif ! cat $FILE_BASH | grep -qF "${name}=\"${value}\""; then + sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $FILE_BASH fi - variable=`cat $HOME/.bash_profile | grep -qF "${name}=\"${value}\""` + variable=`cat $FILE_BASH | grep -qF "${name}=\"${value}\""` if ! grep -q "${type}" <<< "$variable"; then - sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $HOME/.bash_profile + sed -i "s%^.*${name}*=.*%${type} ${name}=\"${value}\"%" $FILE_BASH fi fi -sed -i '/^$/d' $HOME/.bash_profile -. $HOME/.bash_profile \ No newline at end of file +sed -i '/^$/d' $FILE_BASH +. $FILE_BASH \ No newline at end of file