
我想知道您是否有文件名稱> abc (1).bin
或> abc (1).txt
文件,如何讀取它們。這些檔案在.bin
或副檔名之前帶有空格和括號.txt
。
要讀取 .bin 文件,我有一個工具,如果從文件名中刪除“空格和 (1)”,我可以輕鬆讀取它。但是當我有這個空格和括號(1).bin
名稱時,我無法讀取它。
當我cat
創建.txt
文件時,它可以工作..但它不適用於該.bin
文件。以下是要求的測試:
$ cat full_logs-10.2.0.103-2018.02.07\ \(1\).txt
hello,
this is a test.
--------xxxxxxx------xxxxxxx------------xxxxxxx--------
$ LogAnalyzeRebirth -p -x ./ full_logs-2018.02.07\ \(1\).bin
usage: LogAnalyzeRebirth [-h] [-A] [-B] [-C] [-D] [-E] [-F]
[-G GRAPH [GRAPH ...]] [-H] [-I [HISTOGRAM]] [-L]
[-M] [-N] [-P [PDF]] [-R] [-S] [-T] [-U] [-V] [-b]
[-c] [-e] [--moo] [-f] [-g] [-i] [-k] [-l] [-m] [-n]
[-o] [-p PATH] [-q] [-r] [-s] [-t] [-v] [-x EXTRACT]
[-z]
LogAnalyzeRebirth: error: argument -p/--path: expected 1 argument(s)
--------xxxxxxx------xxxxxxx------------xxxxxxx--------
$ LogAnalyzeRebirth.py -p ./ -x "full_logs-10.2.0.103-2018.02.07 (1).bin"
(\ /) (\ /)
( . .) LogAnalyzeRebirth (. . )
c(")(") (")(")o
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
Extract failed.
LogAnalyzeRebirth can't find full_logs-10.2.0.103-2018.02.07 (1).bin
No such file or directory : ./full_logs-10.2.0.103-2018.02.07 (1)/dmesg
--- Firmware_version ---
No such file or directory : ./full_logs-10.2.0.103-2018.02.07 (1)/version.txt
--------xxxxxxx------xxxxxxx------------xxxxxxx--------
答案1
評論中的討論表明,奇怪的檔案名稱必須傳遞給腳本或程序,該腳本或程式本身正在以檔案名稱作為參數呼叫其他腳本或程式。因此,將檔案名稱括在引號中是不夠的,因為 shell 會刪除這些引號,而下次呼叫會傳輸不含引號的檔案名,使其無法使用。
所以我的想法是使用doLogAnalyze
LogAnalyzeRebirth.py 的包裝腳本,如下所示:
#!/bin/bash
tmpfile=$(mktemp /tmp/LogAnalyzeRebirth.XXXXXX) # create temporary file
cp "$1" "$tmpfile" # copy to temporay file
LogAnalyzeRebirth.py -p ./ -x "$tmpfile" # analyze copy
rm "$tmpfile" # delete copy
./doLogAnalyze "full_logs-10.2.0.103-2018.02.07 (1).bin"
無論主程式中使用了多少其他程序,呼叫都應該完成這項工作。正如OP所希望的那樣,原始文件沒有進行任何更改。