Bash bad substitution with subshell and substring

前端 未结 6 773
旧巷少年郎
旧巷少年郎 2021-02-12 10:26

A contrived example... given

FOO=\"/foo/bar/baz\"

this works (in bash)

BAR=$(basename $FOO) # result is BAR=\"baz\"
BAZ=${BAR         


        
6条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 11:12

    A contrived solution for your contrived example:

    BAZ=$(expr $(basename $FOO) : '\(.\)')
    

    as in

    $ FOO=/abc/def/ghi/jkl
    $ BAZ=$(expr $(basename $FOO) : '\(.\)')
    $ echo $BAZ
    j
    

提交回复
热议问题