使用sarge运行shell脚本会吃掉我的引号

时间:2017-12-25 09:05:29

标签: python linux shell subprocess sh

我正在尝试使用sarge库执行shell脚本。 我的文件script.sh包含以下内容:

#!/usr/bin/env sh
export LOCAL_PROJECT_ROOT=/path/to/the/dir
inotifywait -mr --exclude '(.git|.idea|node_modules)' \
-e modify,create,delete ${LOCAL_PROJECT_ROOT} --format '%w%f'

我和sarge一样运行它:

sarge.run('sh script.sh')

我看到htop没有inotifywait进程正在运行。 但是,当我使用sh script.sh直接在shell中运行此脚本时,一切都按预期工作。

如果删除包含引用参数的--exclude--format部分,sarge也可以运行。

如果我将脚本重写为这样的话,它也可以运行sarge:

echo "inotifywait -mr --exclude '(.git|.idea|node_modules)' -e modify,create,delete ${LOCAL_PROJECT_ROOT} --format '%w%f'" | /bin/sh

1 个答案:

答案 0 :(得分:1)

听起来像模块问题。

因为:

private static char[][] ParseFile(string file)
    {
        string[] fileOne = File.ReadAllLines(file);
        char[][] fileOut = {};
        char[] fileOutLine;
        for (int i = 0; i < fileTwo.Length ; i++)
        {
            string linew = fileTwo[i];
            for (int j = 0; j < linew.Length; j++)
            {
                //Stuck here
            }
        }

        return fileOut;  
private static char TurntoChar(string s)
    {
        switch (s)
        {
                case "S":
                    return 'S';
                    break;
                case "O":
                    return 'O';
                    break;
                case "F":
                    return 'F';
                    break;
                default:
                    return 'B';
                    break;
        }
    }
}


internal class Point
{
    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }

    public int Y { get; set; }
    public int X { get; set; }
}

}        

也许:

Python 2.7.6 (default, Nov 23 2017, 15:49:48) 
[GCC 4.8.4] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> 'a' == "a"
True
>>> '%s' %"'a'"
"'a'"
>>> "%s" %'"a"'
'"a"'
>>> 
  1. 转义字符未定义'\'check this
  2. 下一行字符为#!/usr/bin/env sh export LOCAL_PROJECT_ROOT=/path/to/the/dir inotifywait -mr --exclude "(.git|.idea|node_modules)" -e modify,create,delete ${LOCAL_PROJECT_ROOT} --format "%w%f" ,但您有“\\ n”
  3. 您只运行\n 这对壳牌来说还不够。