预定在Windows上运行一个bash shell脚本(问题2) [英] schedule running a bash shell script in windows (question2)
问题描述
一个preciate任何帮助和原谅我,如果我的术语不正确。
出租车从这个问题<一期建设上href=\"http://stackoverflow.com/questions/21517909/schedule-running-a-bash-shell-script-in-windows\">here:
Apreciate any help and excuse me if my terminology is incorrect.
building on from this question here:
我试图运行一个sh文件,我在上面的问题,这基本上是使用应答做到这一点
结果1 - 我的关联文件的 filename.sh 与 filename.bat
结果 filename.bat 是这样的:
i am trying to run a .sh file, and I do this by using the answer in the question above, which is basically
1 - associating my file filename.sh with the filename.bat
filename.bat looks like this:
@echo off
c:
chdir c:\cygwin\bin
bash --login %*
这一般适用于大多数的我* .SH文件,一个例子是这样的:
This generally works for most of my *.sh files with an example being this:
#!/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' '{}' ';'
所以上面的作品时,我双击它。
So the above works when I double click on it.
有些情况下我注意到,当我对他们双击不工作,是当脚本包含像下面的内容:
结果1->搜索
Some instances I have noted that do not work when I double click on them, is when the script contains something like below:
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
?
What I am wondering is why is 1 and 2 above not work for me, by double clicking on them, when they do work by invoking the command ./filename.sh
?
请注意:我在Windows XP上运行的cygwin
Note: I am running cygwin on windows XP
编辑:这是我所得到的,当我说它不工作,双击它在cmd窗口打开并显示此
This is what I get when I say it does not work by double clicking it in that the cmd window opens up and displays this.
FormatCSVFiles.sh是我双击该文件。
FormatCSVFiles.sh is the file I am double clicking on.
推荐答案
更正:这实际工作。我没有给echo命令之前,改变目录。因此,通过我一个愚蠢的错误。 TKS。
Correction: this actually works. I was not changing directory before giving the echo command. So a silly mistake by me . tks.
这篇关于预定在Windows上运行一个bash shell脚本(问题2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!