سؤال

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