2016-10-15 19 views
1

我正在讀取bash腳本中的變量的字符串(存儲在另一個文件中的文件的名稱)。
我原來的命令來運行是量角器conf.js僅當通過批處理腳本的變量運行時纔給出'未找到規格'

protractor conf.js --specs 'LeadershipBoard.js' 

如果直接在腳本文件中寫入了工作良好。但下面的行不通。

protractor conf.js --specs $value 

並返回「未找到規格,完成0秒」。這是我的RunConf.sh文件

#!/bin/bash 
value=$(<string.txt) 
echo $value   // 'LeadershipBoard.js' 

commandForConf="protractor conf.js --specs $value" 
echo $commandForConf // protractor conf.js --specs 'LeadershipBoards.js' 

eval "$commandForConf" // No specs found 
eval "protractor conf.js --specs 'LeadershipBoard.js'" // 6 specs found, 0 failures 

我想eval「$ commandForConf」工作。這裏是日誌控制檯

$ sh RunConf.sh 
'LeadershipBoard.js' 
protractor conf.js --specs 'LeadershipBoard.js' 
[15:49:35] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
[15:49:35] I/launcher - Running 1 instances of WebDriver 
Started 

No specs found Finished in 0 seconds 

[15:49:46] I/launcher - 0 instance(s) of WebDriver still running 
[15:49:46] I/launcher - internet explorer11 #01 passed 
[15:49:54] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
[15:49:54] I/launcher - Running 1 instances of WebDriver Started 


6 specs, 0 failures Finished in 58.478 seconds 
[15:51:00] I/launcher - 0 instance(s) of WebDriver still running 
[15:51:00] I/launcher - internet explorer11 #01 passed 
+0

它的絕對文件權限問題。檢查一下! –

回答

0

我發現錯誤來自文件「string.txt」,我將其保存爲文件js函數的HTML保存數據。它有一個奇怪的字符,它不會顯示在shell的echo或記事本文本中。

當我看到那個字符時,我試着在批處理文件中重複這些步驟。我用js正則表達式剝離了字符。這解決了這個問題。

相關問題