1
我無法分辨如何使用雙引號來捕獲命令行參數的bash腳本。我有兩個文件:hello_world
和hello world
(請注意第二個文件名中的空格)。
當然這個工程:
#!/usr/bin/env bash
ls "[email protected]"
$ ./quoted_args.sh hello_world "hello world"
hello world hello_world
然而,沒有下面的(非常相似)腳本的工作:
腳本A:
#!/usr/bin/env bash
FILES="[email protected]"
ls "$FILES"
$ ./quoted_args.sh hello_world "hello world"
ls: hello_world hello world: No such file or director
腳本B:
#!/usr/bin/env bash
[email protected]
ls "$FILES"
$ ./quoted_args.sh hello_world "hello world"
ls: hello_world hello world: No such file or director
腳本C:
#!/usr/bin/env bash
FILES="[email protected]"
ls $FILES
$ ./quoted_args.sh hello_world "hello world"
ls: hello: No such file or directory
ls: world: No such file or directory
hello_world
腳本d:
#!/usr/bin/env bash
[email protected]
ls $FILES
$ ./quoted_args.sh hello_world "hello world"
ls: hello: No such file or directory
ls: world: No such file or directory
hello_world
我覺得我已經嘗試過這樣做的各種方式。我將不勝感激任何幫助或見解!
謝謝!所有大寫變量會出現什麼問題? –
@ZachKirsch沒什麼。它們通常由shell和應用程序使用,但您可能會重寫其他內容。 – 123
Unix shell使用所有的大寫環境變量,例如'PATH,LINES,LANG'等等,你可以在使用全部大寫變量時重寫其中的一個。 – anubhava