2017-10-12 369 views
0

的文件夾結構設置,像這樣的時候:「沒有這樣的文件或目錄」運行的Makefile腳本

Main directory 
    \_ keyspaces 
    \_ f1 
     \_ bootstrap.cql 
     \_ anotherFolder 
     \_ 0001-something.cql 
    \_ f2 
     \_ bootstrap.cql 
     \_ anotherFolder 
     \_ 0001-something.cql 
     \_ 0002-moreSomething.cql 

我有一個Makefile在主目錄中包含該代碼:

do_stuff: 
    for ks in keyspaces/*; do \ 
     cqlsh -f "$${ks}/bootstrap.cql"; \ 
    done 

當我在我的終端(使用iTerm2)在主目錄內運行make do_stuff時,出現以下錯誤消息:

Can't open 'keyspaces/f1/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f1/bootstrap.cql' 
command terminated with exit code 1 
Can't open 'keyspaces/f2/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f2/bootstrap.cql' 
command terminated with exit code 1 
make: *** [do_stuff] Error 1 

但是,如果我在終端運行這個:cat keyspaces/f1/bootstrap.sql我得到打印出來的文件的內容,所以路徑是正確的,它確實存在,但cqlsh無法識別它?

看着the Cassandra/cqlsh docs,它看起來像我正確使用-f命令,所以我不知道爲什麼我會得到錯誤。

+0

'cat keyspaces/f1/bootstrap.cql'? – Beta

回答

1

我會用簡單的步驟,開始以消除潛在的問題

. 
├── Makefile 
└── keyspaces 
    ├── f1 
    │   └── bootstrap.cql 
    └── f2 
     └── bootstrap.cql 

與下面的Makefile,做工精細

do_stuff: 
    for ks in keyspaces/*; do \ 
     cat "$${ks}/bootstrap.cql"; \ 
    done 

執行

make 
for ks in keyspaces/*; do \ 
     cat "${ks}/bootstrap.cql"; \ 
    done 
a 
b 

仔細檢查,這裏面Main directory你可以致電

cqlsh -f "keyspaces/f1/bootstrap.cql" 

也許你可以委託給find

do_stuff: 
    find `pwd` -name "*.cql" -exec cat {} \; 
+0

第一個使用'cat'的循環可以正常工作,但是,您在'Main directory'內建議運行的最後一行代碼會拋出未找到的錯誤,所以我試圖在Cassandra命令中出現錯誤運行:/我會發布更新,如果我弄明白了。謝謝! – Attila

+0

還有一個問題,也許代替makefile,你可以簡單地使用find?找到'pwd' -name「* .cql」-exec cqlsh -f {} \; – mko

+0

它似乎工作,但是當我在循環中使用它時,我得到'find:-exec:no terminating「;」或「+」' – Attila

相關問題