2012-09-07 78 views
2

我想在一個awk腳本修改工作目錄內的工作目錄:AWK更改腳本

... 
    path="./some/path" 
    system("pwd") ; \ 
    current_dir=system("pwd") ; \ 
    pushd_cmd="pushd " path ; \ # a "cd" doesn't work too 
    print pushd_cmd ; \ 
    system(pushd_cmd) ; \ 
    system("pwd"); \    # the same directory as before 
    type="xml" 
    ls_cmd = "ls *." type;   # so I can't find the files. Specifying with "./some/path/*.xml" doesn't work too (without trying to change the working directory) 
    ... 

是否有人知道爲什麼系統確實在我的情況有沒有影響?

回答

4

system將啓動子進程,並且子進程不能更改其父級的工作目錄。

快速谷歌搜索揭示了GNU AWK文檔的以下部分:http://www.delorie.com/gnu/docs/gawk/gawk_252.html

這似乎暗示着標準AWK沒有改變工作目錄的方法。 (在GNU AWK中,你可以用chdir來做到這一點)。