Bash bad substitution with subshell and substring

前端 未结 6 771
旧巷少年郎
旧巷少年郎 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:17

    It fails because ${BAR:0:1} is a variable expansion. Bash expects to see a variable name after ${, not a value.

    I'm not aware of a way to do it in a single expression.

提交回复
热议问题