github から取得した次のディレクトリ構造があります。
dotfiles/bash
.bashrc
.bash_profile
.some_other
env
dotfiles/tmux/
.tmux.conf
dotfiles/???/
.whatever
bash/私の bashcode (以下) では、(私のスクリプト symlink.sh で) サブフォルダーを反復処理し、すべてではなく特定のドットファイルを ~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