V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gIrl1990
V2EX  ›  问与答

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

  •  
  •   gIrl1990 · 2019-09-06 18:30:23 +08:00 · 957 次点击
    这是一个创建于 1665 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
    

    如何让这个目录展开?

    第 1 条附言  ·  2019-09-07 02:36:45 +08:00

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

    echo "${REPLY[0]}"
    echo "${REPLY[@]}"
    
    第 2 条附言  ·  2019-10-09 22:40:25 +08:00

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

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

    2 条回复    2019-09-06 18:50:32 +08:00
    ps1aniuge
        1
    ps1aniuge  
       2019-09-06 18:39:54 +08:00
    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  
       2019-09-06 18:50:32 +08:00   ❤️ 1
    ls `eval echo $REPLY`
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1032 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:25 · PVG 06:25 · LAX 15:25 · JFK 18:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.