V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
gIrl1990
V2EX  ›  问与答

Bash Expansion 路径名展开, 如果是输入字符串,怎么办?

  •  
  •   gIrl1990 · Sep 6, 2019 · 1354 views
    This topic created in 2424 days ago, the information mentioned may be changed or developed.

    see: https://blog.wentao.me/the-linux-command-line/2014/05/09/bash-expansion.html

    bash-3.2$ read
    ~/.bash_profile
    bash-3.2$ echo "$REPLY"
    ~/.bash_profile
    bash-3.2$ ls $REPLY
    ls: ~/.bash_profile: No such file or directory
    bash-3.2$ ls "$REPLY"
    ls: ~/.bash_profile: No such file or directory
    

    如何让这个目录展开?

    Supplement 1  ·  Sep 7, 2019

    这里搞错了,REPLY 是一个数组,反正了解意思就行。

    echo "${REPLY[0]}"
    echo "${REPLY[@]}"
    
    Supplement 2  ·  Oct 9, 2019

    read [-a aname] [name …] 想要数组的话使用 -a Option

    If no names are supplied, the line read is assigned to the variable REPLY.

    2 replies    2019-09-06 18:50:32 +08:00
    ps1aniuge
        1
    ps1aniuge  
       Sep 6, 2019
    powershell on linux:

    PS /root> $REPLY='~/.bash_profile'
    PS /root> ls $REPLY
    /root/.bash_profile
    PS /root> ls -l $REPLY
    -rw-r--r--. 1 root root 176 12 月 29 2013 /root/.bash_profile
    PS /root>
    conanforever22
        2
    conanforever22  
       Sep 6, 2019   ❤️ 1
    ls `eval echo $REPLY`
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1259 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:57 · PVG 07:57 · LAX 16:57 · JFK 19:57
    ♥ Do have faith in what you're doing.