What needs to be done to ensure that a parameter containing embedded spaces is handled correctly when used within a command substitution? Perhaps an example will illustrate
$ file="/home/1_cr/xy z" $ basename $file xy $ #need to pass basename a quoted $file to prevent the z in 'xy z' from being eaten $ basename "$file" xy z $ #Now using $file inside a command substitution without quoting..... $ #....the command substitution causes 'xy z' to split $ set -- $(basename "$file") $ printf "%s\n" "$@" xy z $ #But quoting the command substitution does not prevent 'xy z'...... $ #....from being split before being passed to basename $ set -- "$(basename $file)" $ printf "%s\n" "$@" xy
What do i need to do so that
$ set -- $(basename $file) $ printf "%s\n" "$@"