2014-02-11 70 views
-1

如果我的術語不正確,請對所有幫助和請諒解。
從這個問題here建立在:在Windows中運行bash shell腳本的計劃(問題2)

我試圖運行一個sh文件,我在上面的問題,這基本上是
1使用的答案做到這一點 - 將我的文件filename.shfilename.bat
filename.bat看起來是這樣的:

@echo off 

c: 
chdir c:\cygwin\bin 

bash --login %* 

這通常適用於大多數我的* .sh文件舉例如下:

#!/bin/bash 

# Configure bash so the script will exit if a command fails. 
set -e 

#this is the DIR i want to copy to 
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 
#this is the DIR i want to copy from 
DIR2=/cygdrive/v/where/file/is 

#cd to the dir where I want to copy the files to: 
cd "$DIR" 

#cp files and subdirectories of interest 
#include the subdirs 
cp -r "$DIR2"/* . 

# This will unzip all .zip files in all subdirectories under this one. 
# -o is required to overwrite everything that is in there 
find -iname '*.zip' -execdir unzip -o {} \; 

# this will delete row 1-6 and the last row of all the csv files 
find ./ -iname '*.csv' -exec sed -i '1,6d;$ d' '{}' ';' 

所以上面的工程,當我雙擊它。

我注意到,當我雙擊它們不工作的一些情況,就是當腳本包含類似如下:
1->

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/PointB 
    echo $DIR > test.txt #the text.txt file will not be created 


2->

#this renames files in a directory, see [here][2] 
for fname in Combined*.csv ; do mv "$fname" "$(echo "$fname" | sed -r 's/[0-9]{14}//')" ; done 

但是1 & 2如果我使用命令從cygwin運行它們,上面的工作將會起作用./filename.sh

我想知道的是,爲什麼上面的1和2不能爲我工作,通過雙擊它們,當它們通過調用命令./filename.sh工作時?

注:我在Windows XP上運行的cygwin

編輯:這是當我說這不通過雙擊該 cmd窗口打開並顯示此工作,我得到什麼。

This is what I get when I say it does not work by double clicking it FormatCSVFiles.sh是我雙擊的文件。

+2

你是什麼意思的「不工作」?是否有錯誤訊息? – tripleee

+0

@tripleee好點,我已經更新了我的問題,讓我知道如果還有其他東西。 – HattrickNZ

回答

0

更正:這實際上有效。在給出echo命令之前,我沒有改變目錄。所以我犯了一個愚蠢的錯誤。韓國社交協會。