-1

If I can search google from the command line on Ubuntu, it would save me a lot of time in my workflow. If I run this it opens up Google.

xdg-open 'https://www.google.com/search?q="searchterm1" "searchterm2"'

I dont know how to make this google.sh accept inputs though.

Essentially I want to run this in the command line

./googler.sh searchterm1 searchterm2 searchterm3 

This will open this Google link in the browser

https://www.google.com/search?q= "searchterm1" "searchterm2" "searchterm3"

1 Answers1

0

If you want to accept an arbitrary number of arguments, you can do something like this:

#!/bin/sh

quote_search_terms() {
    for term in "$@"; do
        echo "\"$term\" "
    done
}

xdg-open "https://www.google.com/search?q=$(quote_search_terms "$@")"

This will give you behavior similar to what you've shown in your question.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Would it be easy to add another site to this - like https://www.bing.com/search?q=searchterm1 This could be really useful if I can open many search windows from the terminal – user3102359 Oct 12 '22 at 13:26
  • 1
    Nice!!! xdg-open "https://www.google.com/search?q=$(quote_search_terms "$@")";xdg-open "https://bing.com/search?q=$(quote_search_terms "$@")" – user3102359 Oct 12 '22 at 13:28