Link to home
Start Free TrialLog in
Avatar of sduser1
sduser1Flag for United States of America

asked on

Help with running batch script

I am trying to get the version of the chrome using the below bash script.

#!/bin/bash

getChrome() {

     if [ -z "$1" ]; then
             echo -e "No arguments specified\n"
     echo -e "Options:
             --version             Displays the version of the chrome
             --location            Displays the location of the chrome profile folder.
             version             Displays the version of the chrome
             location            Displays the location of the chrome profile folder.

             return 0
         fi

         if [[ $1 == version]]; then
             google-chrome --version
             echo 'test'
             return 0
         fi

         if [[ $1 == location]]; then
                      chromeLocation = ""/Users/user1/Library/Application Support/Google/Chrome/Default"
                      return 0
                  fi
}
export -f getChrome


when i run the command in the bash terminal getChrome --version, it is not printing the version. Please help.
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sduser1

ASKER

Thank you. I replaced the above in the below piece of code. I did not get the version printed when i use the command  getChrome --version

if [[ $1 == version]]; then
              /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
             echo 'test'
             return 0
         fi
Avatar of sduser1

ASKER

Question:

Do you know the command that is used to get the chrome version in linux OS?

i got the below for mac and it worked fine.

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version

Thanks
Avatar of skullnobrains
skullnobrains

you are checking for "version" rather than "--version"

use

if [[ "X$1" == X--version]]

or rather a case/esac statement
@sduser1
If using windows
a)
we can view the same using:
C:\Windows\regedit.exe
HKEY_CURRENT_USER
Software
Google
Chrome
BLBeacon
value of "version"
b)
Same thing using bash.exe at Windows:

CHROME_VERSION=$(/cygdrive/c/Windows/System32/reg.exe QUERY "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version  | /usr/bin/awk '"version" == $1 { print $NF}')
echo $CHROME_VERSION
OR
/cygdrive/c/Windows/System32/reg.exe QUERY "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version  | /usr/bin/awk '"version" == $1 { print $NF}'
OR
echo $(/cygdrive/c/Windows/System32/reg.exe QUERY "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version  | /usr/bin/awk '"version" == $1 { print $NF}')
OR
/cygdrive/c/Windows/System32/reg.exe QUERY "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" | /usr/bin/awk '"version" == $1 { print $NF}'
OR inside C:\Windows\System32\cmd.exe
C:\Windows\System32\wbem\WMIC.exe datafile where name="C:\\PROGRA~2\\Google\\Chrome\\Applic~1\\chrome.exe" get Version /value
am i crazy or was the question edited ???

"-version" was changed to "--version" in the command line

the test line was edited so the test string dis not start with a "-". it will still break if the user provides one, btw.
@sduser1, You're welcome!

Good luck!