Article 6NT3Y Make ls case insensitive inside a script

Make ls case insensitive inside a script

by
trafikpolisen
from LinuxQuestions.org on (#6NT3Y)
Hi!

I would like to be able to list files regardless of upper or lower case filenames. Background is that I've made a bash script that uses ls, but then formats the listing in the specific way that I want, i.e. file names in the first column, then size, then date in a specific format, then attributes, then owner. It isn't completely flawless, but works great 99% of the time. I have read that you shouldn't use the output of ls like this, according to the link below, but I'm to thick to comprehend why:D
https://mywiki.wooledge.org/ParsingLs
Anyway... Say I have three files named "abc", "ABC" and "aBc" and I want them all to show up when do "ls -l abc". I googled around and found this solution:
Code:(shopt -s nocaseglob; ls -l abc*)I need to use a wildcard at the end, but that could be OK. However, If I would now make a script out of this example like this:
Code:#!/bin/bash

shopt -s nocaseglob
ls -l "$@"And then run this script like Code:myscript abc* it doesn't work. If I understand it reasonably correctly, it's because the shell expands the wildcard before it reaches "inside" the script. Is there an easy way to get around this?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments