문제

I've been trying to get the following two commands into one command:

var=$(find dir/* -name "$file")
var=$(basename "$var")

I thought this might work:

var=$(basename $(find dir/* -name "$file"))

I also tried pipeline, but no luck

Any thoughts?

도움이 되었습니까?

해결책

Add another set of quotes:

var=$(basename "$(find dir/* -name "$file")")

다른 팁

Use the -exec option of the command find to apply the basename command on each result:

var=$(find dir/* -name "$file" -exec basename {} ';')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top