2014-01-07 41 views
0

我使用Nitrous.io作为一些基本的开发工具,代码使用git进行管理。 我想用一个脚本来设置我的开发机器上的git项目(Nitrous,work和home之间有几个)。 [编辑:混帐回购协议有两个轨道项目下,能有更多]设置Github项目的Bash脚本

我有以下几点:

#!/bin/bash 
current=${1-`pwd`} 
echo "Starting directory is $current" 
cd $current 
read -p "Press [Enter] key to start install..." 

git init 
git remote add nitrous https://github.com/[user]/[project].git 
git pull nitrous master 

for dir in "$(find $current -mindepth 1 -maxdepth 1 -type d -name '[!.]*')"; 
    do 
    echo "Setting up $dir" 
    #cd $dir 
    #bundle install 
    #rake db:migrate 
    done 

    cd $current 
    exit 0 

但它无法改变目录。 (我注释掉的那一刻轨动作)有线索,为什么

[email protected]:~/workspace$ ../setup.sh                                   
Starting directory is /home/action/workspace                                   
Press [Enter] key to start install...                                     
Initialized empty Git repository in /home/action/workspace/.git/                              
remote: Counting objects: 175, done.                                     
remote: Compressing objects: 100% (128/128), done.                                  
remote: Total 175 (delta 31), reused 175 (delta 31)                                 
Receiving objects: 100% (175/175), 29.44 KiB | 0 bytes/s, done.                              
Resolving deltas: 100% (31/31), done.                                     
From https://github.com/[user]/[project]                                    
* branch   master  -> FETCH_HEAD                                   
* [new branch]  master  -> nitrous/master                                  
Setting up /home/action/workspace/testlog                                    
/home/action/workspace/testembedded 

有人吗?

问候

回答

0

cd在shell脚本中的cd运行该脚本,不是你的交互shell的外壳。

除非用.执行,否则你不能做你想做的。

0

编辑,这为我工作:

res="$(find $current -mindepth 1 -maxdepth 1 -type d -name '[!.]*')" 
for dir in $res 
do 
    echo "$dir" 
    ls -la  
done 
+0

哎迈克尔,捆绑和耙命令不在子目录。 Rake确实允许我将RakeFile指定为参数,因此我可以使用“rake -f testlog/Rakefile db:migrate”从较高级别的目录中调用该参数,但捆绑调用没有该选项。 – NZM

+0

请参阅上面的编辑。如果你在“$(find $ current -mindepth 1 -maxdepth 1 -type d -name'[!。] *')”中找到dir, do echo“设置$ dir”$ dir将在第一次迭代中包含所有可用的dirs。你不能进入那个... –