I'm using a dotfile manage software, named dotdrop. Using a config file named .env
, contents like: git_folder="~/code/Git"
.
Also use a script to setup this dotfile tool before the first use of it, as follows,
#!/bin/bash
env1="~/Dropbox/.env"
env2="/mnt/d/Dropbox/.env"
if [ -f $env1 ]; then
echo "Found dotdrop env file, installing dotfiles..."
source $env1
eval $(grep -v "^#" $env1) dotdrop --cfg=${git_folder}/dotfiles/config.yaml install
elif [ -f $env2 ]; then
echo "Found dotdrop env file, installing dotfiles..."
source $env2
eval $(grep -v "^#" $env2) dotdrop --cfg=${git_folder}/dotfiles/config.yaml install
else echo "Pls sync environment files first!"
fi
If I store my config file at ~/Dropbox/.env
, when I run the script, I just got "Pls sync environment files first!"
(run in if condition is expected). If config file stored at /mnt/d/Dropbox/.env
, the script will go through the elif condition, which is expected.
Find the reason until I run the script in dubug mode, and get the difference:
➜ scripts git:(master) ✗ bash -x dotdrop_setup.sh
+ env1='~/Dropbox/.env'
+ env2=/mnt/d/Dropbox/.env
+ '[' -f '~/Dropbox/.env' ']'
+ '[' -f /mnt/d/Dropbox/.env ']'
+ echo 'Pls sync environment files first!'
Pls sync environment files first!
So, I think the difference between ~
and /home/user
is the reason.
After I change ~
to /home/roach
(roach is user name), it works.
➜ scripts git:(master) ✗ bash -x dotdrop_setup.sh
+ env1=/home/roach/Dropbox/.env
+ env2=/mnt/d/Dropbox/.env
+ '[' -f /home/roach/Dropbox/.env ']'
+ echo 'Found dotdrop env file, installing dotfiles...'
Found dotdrop env file, installing dotfiles...
+ source /home/roach/Dropbox/.env
++ git_folder='~/code/Git'
++ grep -v '^#' /home/roach/Dropbox/.env
+ eval git_folder='~/code/Git'
++ dotdrop '--cfg=~/code/Git/dotfiles/config.yaml' install
_ _ _
__| | ___ | |_ __| |_ __ ___ _ __
/ _` |/ _ \| __/ _` | '__/ _ \| '_ |
\__,_|\___/ \__\__,_|_| \___/| .__/ v0.22.0
|_|
0 dotfile(s) installed.
The debug shows ''
surround + env1='~/Dropbox/.env'
is removed which I think is the reason.
But, WHY?
Additional question,
alias dotdrop="eval $(grep -v "^#" $env1) /usr/bin/dotdrop --cfg=${git_folder}/dotfiles/config.yaml install"
is a config add to bashrc
, zshrc
, etc. It doesn't work if I add it to my script directly!
Finally, found I have to add source $env
,
So WHY it works in a bashrc file?
user
you mentioned in question? – Prvt_Yadav Oct 22 '18 at 06:22Tilde (~) not expand inside double quotes
notWHY Tilde (~) not expand inside double quotes?
. Cause if I kownTilde (~) not expand inside double quotes
I will not ask this question. – roachsinai Oct 22 '18 at 12:33