Variables value gets lost in subshell

前端 未结 5 1304
忘了有多久
忘了有多久 2020-12-21 09:57

This bash script concatenates the names for jar files to a classpath (variable CP), in the while loop the value is correct but is lost in the subshell as descibed in this re

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 10:27

    You might find using find a bit more versatile.

    For example:

    export CP=$( find /home/depesz/q/ -maxdepth 1 -type f -name '*.jar' -printf ':%p' | cut -b 2- )
    

    Of course set of find options is dependant on what you need/want.

    This one is closer to what you had previously:

    export CP=$( find . -maxdepth 1 -type f -name '*.jar' -printf ':%f' | cut -b 2- )
    

提交回复
热议问题