you can strip any last character with just string[:-1]
could you provide an example of how you'd use
I'm trying to remove the * from an executable filename when doing an ls -lCode:string[:-1]
Maybe you don't need to remove the last char at all.
It's possible that you're getting the trailing * on some files because your "ls" command has the "-F" option, which appends a filetype classifier character to the filename.
This may be the case even if you are not explicitly providing the "-F" yourself, often ls gets aliased to something that has some useful default options.
Try using "\ls -l" (ls with a leading backslash) to get an unaliased ls, and see if that solves your issue.
You shouldn't be parsing the output of ls in the first place. ls is designed for human readers; it's impossible to reliably parse its output regardless of which options you pass to it because you can't always tell where filename boundries are. Remember, a filename can contain ANY whitespace character, including \n. Instead, use your language's facility for handling filenames. E.g.,Code:#Bash for i in *; do # do stuff done #Ruby Dir.open(some_dir) do |dir| dir.each do |file| next if file =~ /^[.]+$/ # do stuff end end
What language was this supposed to be in anyway?
Indeed, tell us what language and we will be glad to help
MIke
he is doing a ls -l. I am certain that's not a shell command.
sed -ie 's/.$//' filename
Bookmarks