BlackEnvil wrote: > Description: using ` ` or $() with command that use dirnames with spaces > fail. > > there are diferent dirnames with this problem, and different situations that > cause these errors, not only with ls and not only with grep. > > bye > > > Repeat-By: > > [blacken...@space_star ~]$ cd $HOME; mkdir hello\ -world/; touch test; echo > "ls hello\ -world/" > test; $(grep ls test); > ls: invalid line width: orld/ > [blacken...@space_star ~]$
There are actually two problems here. After the command substitution, the shell does word splitting, and the command it sees is this (spaced for readability): ls hello\ -world ^^^^^^ ^^^^^^ arg1 arg2 The -world part is interpreted as the option -w to ls, and "orld" as the argument to that option, which is an invalid line width. To fix that, use -- to mark the end of options. But even if you do that, you would still get an error because ls would see two filenames: "hello\" and "-world", neither of which exists. > [blacken...@space_star ~]$ cd $HOME; mkdir hello-\ world/; touch test; echo > "ls hello-\ world/" > test; $(grep ls test); > ls: cannot access hello-\: No such file or directory > world/: > [blacken...@space_star ~]$ Same as above: the shell does word splitting on the result of command substitution, and what it sees is the command (spaced for readability) ls hello-\ world ^^^^^^^ ^^^^^ arg1 arg2 since those files or directory do not exist, ls correctly produces an error. In both cases what you're seeing is not a bug, but just expected behavior. -- D.