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