How to Prevent Error from ls Command?
Hello All,
SHELL: Bash v4.1.10(1) ls --version: ls (GNU coreutils) 8.9 From the ls man page it says you can use "ls -1" (*that's a "-" and a number ONE) to list the files in a directory, one file per line. The command works just fine entering it on the command line like "# ls -1", but when I try to use it with the $(..) structure along with IFS=newline I get an error and then ls stops working until I open a new terminal window... For Example: Code:
# ls -1 Code:
# IFS=" I also got that error when executing from inside a script, but it doesn't seem to cause an issue inside my bash script, just on the CLI. Any thoughts or suggestions would be much appreciated! Thanks in Advance, Matt |
Works just fine on my systems on bash 4.1.2, 4.1.7, and 4.3.26. What distro/version are you using?
|
it works for me using bash 4.3.30 and believe me it is not a bug of ls, but probably a bug of bash - because it parses the command line incorrectly and passes something "strange" to ls.
Remember, at first always the shell itself tries to understand what you entered, tries to expand some possible variables and finally the result will be passed to the command. you may try to use strace to check that. |
Hey Guys, thank you both for the replies...
Did you both make sure to set IFS to a newline, otherwise you won't get the error... Like this: --------- IFS=" " --------- I know its older but I'm running: Code:
> bash --version too sure. And also it ONLY happens when I set IFS to a newline... It also happened to me on a server running Bash 3.1.17.. But, since it seems to work just fine in my Bash script I'm not too worried about it, I was just curious why something like that would be happening. Thanks again for the replies, much appreciated! Thanks Again, Matt |
Quote:
Code:
$ bash --version ARRAY=( $(\ls -1tr) ) |
Hey, thanks again for the reply!
Yes sir... That did work and did NOT throw any error! And yes, there are a few aliases setup for ls. Code:
alias l='ls -alF' Thanks AGAIN, Matt |
Definitely. It must be something in $LS_OPTIONS that's messing things up. The backslash in front of the command forces it to skip any aliases and run the "real" command, eg:
Code:
$ alias ls="echo" |
Ok cool... That's good enough for me!!
Thanks for the explanations much appreciated, that was bothering the heck outta me..! Thanks AGAIN, Matt |
All times are GMT -5. The time now is 04:36 AM. |