计划在Windows中运行bash shell脚本(问题2)

时间:2014-02-11 03:25:11

标签: windows bash shell cygwin

如果我的术语不正确,请提供帮助,请原谅。 从这个问题here开始:

我正在尝试运行.sh文件,我通过使用上面问题中的答案来实现这一点,基本上就是这样
1 - 将我的文件 filename.sh filename.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&如果我使用命令./filename.sh

从cygwin运行它们,则上面的2将起作用

我想知道为什么上面的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是我双击的文件。

1 个答案:

答案 0 :(得分:0)

更正:这确实有效。在给出echo命令之前我没有更改目录。这是我的一个愚蠢的错误。 TKS。