简体   繁体   English

Cygwin在shell脚本中找不到文件

[英]Cygwin can't find files in shell script

I am running a shell script in Cygwin, and the files in the shell script aren't showing up, even though they are definitely in the same directory as the shell script.我在 Cygwin 中运行 shell 脚本,并且 shell 脚本中的文件没有显示,即使它们肯定与 shell 脚本在同一目录中。

Cygwin command: Cygwin 命令:

$ bash `cygpath --unix "C:\Users\myName\Documents\projectFile\dygraphsMaster\generate-combined.sh"`

Shell script (from dygraphs.com ): Shell 脚本(来自dygraphs.com ):

#!/bin/bash
# Generates a single JS file that's easier to include.

GetSources () {
  # This list needs to be kept in sync w/ the one in dygraph-dev.js
  # and the one in jsTestDriver.conf. Order matters, except for the plugins.
  for F in \
    dashed-canvas.js \
    dygraph-options.js \
    dygraph-layout.js \
    dygraph-canvas.js \
    dygraph.js \
    dygraph-utils.js \
    dygraph-gviz.js \
    dygraph-interaction-model.js \
    dygraph-tickers.js \
    dygraph-plugin-base.js \
    plugins/*.js \
    dygraph-plugin-install.js \
    datahandler/datahandler.js \
    datahandler/default.js \
    datahandler/default-fractions.js \
    datahandler/bars.js \
    datahandler/bars-custom.js \
    datahandler/bars-error.js \
    datahandler/bars-fractions.js 
  do
      echo "$F"
  done
}

# Pack all the JS together.
CatSources () {
  GetSources \
  | xargs cat \
  | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,'
}

Copyright () {
  echo '/*! @license Copyright 2014 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */'
}

CatCompressed () {
  Copyright
  CatSources \
  | grep -v '"use strict";' \
  | node_modules/uglify-js/bin/uglifyjs -c warnings=false -m
}

ACTION="${1:-update}"
case "$ACTION" in
ls)
  GetSources
  ;;
cat)
  Copyright
  CatSources
  ;;
compress*|cat_compress*)
  CatCompressed
  ;;
update)
  CatCompressed > dygraph-combined.js
  chmod a+r dygraph-combined.js
  ;;
*)
  echo >&2 "Unknown action '$ACTION'"
  exit 1
  ;;
esac

In which directory are you when executing this? 在执行此操作时您在哪个目录中? In the same folder as the script itself? 在与脚本本身相同的文件夹中?

Can you try this: 你能试试这个:

cd /cygdrive/c/Users/myName/Documents/projectFile/dygraphsMaster/
./generate-combined.sh

You're using backslashes in a unix context - they're going to be treated as escapes. 你在unix上下文中使用反斜杠 - 它们将被视为转义。

eg 例如

marc@host ~
$ ls c:\users
ls: cannot access c:users: No such file or directory
                    ^---look, mom! No slashes!

marc@host ~
$ ls c:\\users
adm1n    Default User         DefaultAppPool  LocalAdm1n  Public
etc...

So... 所以...

$ bash `cygpath --unix "C:\\Users\\myName\\etc...

Often this is related to the EOL characters.通常这与 EOL 字符有关。

Try:尝试:

dos2unix generate-combined.sh dos2unix generate-combined.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM