我有以下目录结构,我从github获取;
dotfiles/bash
.bashrc
.bash_profile
.some_other
env
dotfiles/tmux/
.tmux.conf
dotfiles/???/
.whatever
bash /在我的bashcode(下面)中我想(在我的脚本symlink.sh中)通过子文件夹和符号链接迭代某些(而不是所有)dotfiles到我的~home目录。我怎么能动态地做到这一点?由于我不知道有多少个子文件夹,以及那些我想要符号链接的子文件夹中的文件必须动态完成。
我的代码
!/bin/bash
############################
# .make.sh
# This script creates symlinks from the home directory to any desired dotfiles in ~/dotfiles
############################
set -x
trap read debug
########## Variables
dir=~/dotfiles # dotfiles directory
olddir=~/dotfiles_old # old dotfiles backup directory
files=".bashrc .bash_profile env .tmux.conf" # list of files/folders to symlink in homedir
##########
# create dotfiles_old in homedir
echo "Creating $olddir for backup of any existing dotfiles in ~"
mkdir -p $olddir
echo "...done"
# change to the dotfiles directory
echo "Changing to the $dir directory"
cd $dir
echo "...done"
paus -p ;clear
# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks
for file in $dir/*/*; do
echo $dir;ls -a
if [[ -f $dir/${files##*/} && ! -L $dir/${files##*/} ]]; then
$olddir=$(mktemp -d olddotfiles.XXXXXX)
#mv "~/${files##*/}" "$backupdir"
ls -a
ln -s "$files" ~/${files##*/}
fi
done
答案 0 :(得分:0)
只需使用find命令 - 更改:
for file in $dir/*/*; do
对此:
for file in $(find $dir); do