【问题标题】:schedule running a bash shell script in windows (question2)安排在 Windows 中运行 bash shell 脚本(问题 2)
【发布时间】:2014-02-11 03:25:10
【问题描述】:

感谢任何帮助,如果我的术语不正确,请原谅。
基于这个问题here

我正在尝试运行一个 .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

但是如果我从 cygwin 使用命令 ./filename.sh 运行它们,上面的 1 和 2 将起作用

我想知道的是为什么上面的 1 和 2 对我不起作用,通过双击它们,当它们通过调用命令 ./filename.sh 起作用时?

注意:我在 windows XP 上运行 cygwin

编辑:当我说双击它不起作用时,这就是我得到的结果,因为 cmd 窗口打开并显示它。

FormatCSVFiles.sh 是我双击的文件。

【问题讨论】:

  • “不工作”是什么意思?有错误信息吗?
  • @tripleee 好点,我已经更新了我的问题,如果还有其他问题请告诉我。

标签: windows bash shell cygwin


【解决方案1】:

更正:这确实有效。在给出 echo 命令之前,我没有更改目录。所以我犯了一个愚蠢的错误。 tks。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多