l0ckm4 l0ckm4 - 4 months ago 7
Linux Question

Linux Bash Script - match lower case path in argument with actual filesystem path

I have a linux script that gets an argument passed to it that originates from MSDOS (actually DOSEMU running MS DOS 6.22). The argument that gets passed is case insensitive (as DOS didn't do cases) but of course Linux does.

I am trying to get from the following passed argument

/media/zigg4/vol1/database/scan/stalbans/docprint/wp23452.wpd


to

/media/zigg4/vol1/Database/SCAN/STALBANS/DOCPRINT/Wp23452.WPD


I do not know the actual case sensitive path so I need to somehow determine it from the argument that is passed to the script. I have absolutely no idea where to start with this so any help is greatly appreciated.

edited for extra information and clarity

UPDATE

Thanks to the answer by @anubhava I used the following:-

#!/bin/bash

copies=1
if [ ! -z "$2" ]; then
copies=$2
fi

find / -readable -ipath $1 2>&1 | grep -v "Permission denied" | while IFS= read -r FILE; do
lpr -o Collate=True -#$copies -sP $FILE
done


Works great :-)

Answer

You can use -ipath option of find for ignore case path matching:

# assuming $arg contains path argument supplied
find . -ipath "*$arg*"
Comments