Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
xiawenhao
V2EX  ›  Linux

如果当前文件夹下只有一个文件,用 `ls` 命令获得文件名作为另一个命令的参数,如果文件名有空格怎么办?

  •  
  •   xiawenhao · Apr 20, 2018 · 3844 views
    This topic created in 2970 days ago, the information mentioned may be changed or developed.

    例如在命令行中这样使用,如果文件名有空格怎么办?

    python python-script.py `ls`
    
    6 replies    2018-04-21 18:46:20 +08:00
    goreliu
        1
    goreliu  
       Apr 20, 2018   ❤️ 1
    python python-script.py "`ls`"
    psyche
        2
    psyche  
       Apr 20, 2018   ❤️ 3
    `ls -Q`
    出来的文件名带引号
    Arnie97
        3
    Arnie97  
       Apr 20, 2018 via Android   ❤️ 1
    虽然楼上几位说的也没错,但是这里根本用不着 ls 啊

    python python-script.py *
    xiawenhao
        4
    xiawenhao  
    OP
       Apr 21, 2018
    @psyche mac 中 ls 命令没有 -Q 选项。查了一下 linux 有。
    ynyounuo
        6
    ynyounuo  
       Apr 21, 2018
    @psyche
    是 coreutils 的 ls 否则也没有 --color=auto 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3025 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 14:26 · PVG 22:26 · LAX 07:26 · JFK 10:26
    ♥ Do have faith in what you're doing.