本文介绍了计划在windows中运行bash shell脚本(问题2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的术语不正确,请恳求任何帮助,并原谅我。

从这个问题这里



我试图运行一个.sh文件,我使用上面的问题的答案,这基本上是

1 - 将我的文件 filename.sh filename.bat

filename.bat 关联如下:

  @echo off 

c:
chdir c:\cygwin\bin

bash --login%*

这通常适用于我的大多数* .sh文件,例如:

 #!/ bin / bash 

#配置bash如果命令失败,脚本将退出。
set -e

#this是我想要复制到
的DIR DIR =$(cd$(dirname$ {BASH_SOURCE [0]} &&pwd)
#this是我要从
复制的DIR DIR2 = / cygdrive / v /其中/ file /是

#cd到dir我想将文件复制到:
cd$ DIR

#cp文件和感兴趣的子目录
#include子目录
cp -r$ DIR2/ *。

#这将解压缩所有.zip文件在所有子目录下。
#-o需要覆盖其中的所有内容
find -iname'* .zip'-execdir unzip -o {} \;

#这将删除第1-6行和所有csv文件的最后一行
find ./ -iname'* .csv'-exec sed -i'1,6d; $ d''{}'';'

所以上面的工作当我双击它。



有些实例我注意到,当我双击它们时不工作,是脚本包含如下内容:

1->

  DIR =$(cd$(dirname$ {BASH_SOURCE [0]})& & pwd)/ PointB 
echo $ DIR> test.txt#不会创建text.txt文件


2 - >

  #this重命名目录中的文件,请参阅[here] [2] 
for fname in Combined *。 csv; do mv$ fname$(echo$ fname| sed -r's / [0-9] {14} //'); done

但是1& 2如果我使用命令 ./ filename.sh

$ c
运行它们从cygwin运行它们我想知道是为什么上面的1和2对我来说不起作用,通过双击它们,当他们通过调用命令 ./ filename.sh



注意:我在Windows XP上运行cygwin



编辑:这是我说,双击它即可工作,因为cmd窗口打开并显示此内容。




FormatCSVFiles.sh是我双击的文件。

解决方案

更正:这实际上是工作。我没有改变目录之前给echo命令。所以我的一个愚蠢的错误。 tks。


Apreciate any help and excuse me if my terminology is incorrect.
building on from this question here:

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 %*

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.

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

But 1 & 2 above will work if i run them from cygwin with the command ./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?

Note: I am running cygwin on windows XP

EDIT: 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 is the file I am double clicking on.

解决方案

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:31