On Mon, Dec 30, 2013 at 9:22 AM, Jon Retting <j...@retting.com> wrote: > Hello, > Typed up this one liner function for getting a files actual windows > details/properties information. I needed a tertiary way to compare > executable/drivers, so a version number from windows seemed like a viable > option. Hopefully someone will find this handy, seeing as i feel so guilty > for not contributing more to such a wonderful project like Cygwin. And heck > anything's better than that most recent dosshell thread :) > > #get file details from windows via wmic wmi formatted call condensed > finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo > "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed > 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print > $1"=""\033[1m"$2"\033[0m"}';}
If I'm not mistaken there is at least one superfluous "echo $(" in there. I would also not use $@ since there could be multiple arguments. IIRC you can also omit quotes around $(...) without risking issues with multiple words. finfo() { [ -f "$(cygpath -u "$1")" ] || { echo "bad file: $1" >&2; return 1; } wmic datafile where name=\"$(cygpath -w "$1" | sed 's/\\/\\\\/g')\" get /value \ | sed 's/\r//g;s/^M$//;/^$/d' \ | awk '-F=' '{printf "%s=\033[1m%s\033[0m\n", $1, $2}' } Changed a few more things - error to stderr - line breaks - awk print -> printf Unfortunately I don't have a cygwin handy to test this. I'd also probably not output color coding control characters from this function but rather use tputs to adjust to the terminal at hand. Also sed code can be integrated into awk or replaced by dos2unix, I guess. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple