利用环境变量代替别名
This commit is contained in:
parent
209f3f2185
commit
1774606938
@ -63,27 +63,18 @@ fi
|
|||||||
|
|
||||||
chmod +x "$path/linuxtool/run.sh" &>/dev/null
|
chmod +x "$path/linuxtool/run.sh" &>/dev/null
|
||||||
|
|
||||||
update_alias() {
|
# 创建软链接到 /usr/bin 目录
|
||||||
local file="$1"
|
echo "正在创建软链接..."
|
||||||
if [[ -e "$file" ]]; then
|
ln -sf "$path/linuxtool/run.sh" "/usr/bin/tool"
|
||||||
sed -i '/alias tool.*/d' "$file"
|
chmod +x "/usr/bin/tool"
|
||||||
echo "alias tool='$path/linuxtool/run.sh'" >> "$file"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
shopt -s expand_aliases
|
# 将工具路径写入环境变量配置
|
||||||
alias tool="$path/linuxtool/run.sh"
|
echo "tool='$path/linuxtool/run.sh'" >>/etc/profile
|
||||||
export -f tool &> /dev/null
|
|
||||||
|
|
||||||
for file in "${HOME}/.bashrc" "${HOME}/.profile" "${HOME}/.zshrc" "/etc/profile"; do
|
|
||||||
update_alias "$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "工具箱已经安装成功"
|
echo "工具箱已经安装成功"
|
||||||
echo "位置:${path}/linuxtool"
|
echo "位置:${path}/linuxtool"
|
||||||
echo "命令:tool"
|
echo "命令:tool"
|
||||||
|
|
||||||
|
|
||||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
kill $PPID &>/dev/null
|
kill $PPID &>/dev/null
|
||||||
fi
|
fi
|
@ -3,22 +3,13 @@ declare tool_path=$(cat /etc/profile | grep "tool=" | awk -F "=" '{print $2}' |
|
|||||||
tool_path=$(dirname $tool_path)
|
tool_path=$(dirname $tool_path)
|
||||||
rm -rf $tool_path
|
rm -rf $tool_path
|
||||||
|
|
||||||
remove_alias() {
|
# 删除软链接
|
||||||
local file="$1"
|
if [[ -L "/usr/bin/tool" ]]; then
|
||||||
if [[ -e "$file" ]]; then
|
rm -f "/usr/bin/tool"
|
||||||
sed -i '/alias tool.*/d' "$file"
|
|
||||||
source "$file" &> /dev/null
|
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
for file in "${HOME}/.bashrc" "${HOME}/.profile" "${HOME}/.zshrc" "/etc/profile"; do
|
|
||||||
remove_alias "$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
shopt -u expand_aliases
|
|
||||||
|
|
||||||
unalias tool &> /dev/null
|
|
||||||
|
|
||||||
|
# 从环境变量配置中删除工具路径
|
||||||
|
sed -i '/tool=.*/d' /etc/profile
|
||||||
|
|
||||||
echo "脚本已完整卸载,公众号 lsy22 可获取一键安装脚本"
|
echo "脚本已完整卸载,公众号 lsy22 可获取一键安装脚本"
|
||||||
kill $PPID &>/dev/null
|
kill $PPID &>/dev/null
|
Loading…
Reference in New Issue
Block a user