Shell 批量生成链接

linux程序安装完执行总是要全路径去执行,每一个添加到PATH 又太麻烦,干脆将其生成链接到 ~/bin 目录下,在 /etc/profile 追加一句 export PATH="$PATH:~/bin" ,
#!/bin/bash
#批量生成链接 <1058436713@qq.com>
# 使用 ./xxx.sh [-s] dir [default="~/bin"]
var="" BIN_DIR="" if [ "$1" = "-s" ];then var="true";shift fi if [ -z "$1" ] || [ ! -d $1 ];then echo "Parameter error: \$1";exit 1; fi if [ -z "$2" ];then if [ ! -d ~/bin ];then mkdir ~/bin fi BIN_DIR=~/bin elif [ -n "$2" ] && [ -d $2 ];then BIN_DIR=$2 else echo "Parameter error: \$2";exit 2; fi for file in `ls -al $1 | grep "^-" | gawk '{printf("%s ",$9)}'`;do if [ "$var" = "true" ];then ln -s $1/$file $BIN_DIR/$file else ln $1/$file $BIN_DIR/$file fi done

 

 

 

posted @ 2016-10-09 21:20  x_liang  阅读(291)  评论(0编辑  收藏  举报