Help with running batch script

sduser1
sduser1 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fractional CTO
Distinguished Expert 2018
Commented:
You must use the correct path to Google Chrome, as there's no $PATH entry for any /Applications by default.

Correct way to determine currently installed Google Chrome version...

imac> /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
Google Chrome 75.0.3770.142 

Open in new window

Author

Commented:
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

Author

Commented:
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
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

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

use

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

or rather a case/esac statement
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
@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.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
@sduser1, You're welcome!

Good luck!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial