I am trying to write a script so as to Google-search in terminal. Below is the code :
google.sh
#!/bin/bash
echo "Searching for : $@"
for term in $@ ; do
echo "$term"
$search = $search%20$term
done
open "http://www.google.com/search?q=$search"
Whenever I try to run the script as :
./google.sh some string
I get the error as :
Searching for : some string
some
./google.sh: line 5: =: command not found
string
./google.sh: line 5: =: command not found
Also the google home page opens up in the browser.Please tell me what am I doing wrong here?
I got what was the problem. These are the modifications that I made and my code worked.
#!/bin/bash
echo "Searching for : $@"
for term in $@ ; do
echo "$term"
search="$search%20$term"
done
open "http://www.google.com/search?q=$search"
$
from search
at line 5 $search%20$term
within quotes as "$search%20$term"
I've made this custom aliases. Works for me. OSX
Hope this helps someone!
I added this commands to my .zshrc
alias chrome='{read -r arr; open -a "Google Chrome" "${arr}"} <<<'
alias browser='{read -r arr; chrome ${arr} } <<<'
alias google='{read -r arr; browser "https://google.com/search?q=${arr}";} <<<'
Example:
google 'How do I google from terminal?'
It will open browser of your choice. Chrome for me, but you can also use Safari or Firefox. By passing arguments right into search query you are able to go directly to search results!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With