这段代码旨在将我安装在指定目录下的 /usr/local/python3.9/bin中的执行文件软链接到/usr/bin里面去,避免系统找不到。
运行的时后,输入
sudo /usr/bin/bash .sh 文件名
一定注意usr前面的/
#!/usr/bin/bash
source_dir="/usr/local/python3.9/bin"
destination_dir="/usr/bin"
#确保目标文件夹存在
sudo mkdir -p "$destination_dir"
#遍历源文件夹中的所有文件
for file in "$source_dir"/*; do
#获取文件名
filename=$(basename "$file")
#目标文件的完成路径
destination_file="$destination_dir/$filename"
#检查目标文件夹中是否已经存在同名文件
if [ ! -e "$destination_file" ]; then
#如果不存在,则创建软链接
sudo ln -s "$file" "$destination_file"
echo "创建软链接:$destination_file -> $file"
else echo "跳过,软链接已存在:$destination_file -> $file"
fi
done