Skip to content
Advertisement

Command to list reordered ls columns works in terminal but not through running a script?

I’m trying to make a script that will print information of all files in a given directory in order of owner, group, filename, then permissions separated by commas. The code I wrote works fine when ran in terminal, but when I try to run it through a script with a directory given as $1, it only prints the owner name once and nothing else. What am I overlooking?

here’s the code:

JavaScript

works fine in terminal, but

JavaScript

ran from $script.sh directoryname outputs only the user name once and that’s it.

Advertisement

Answer

Don’t parse ls. Use stat instead

JavaScript

That puts the directory name in the output, so you might want to cd "$1" then use stat ... *


Another option: find

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement