LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2021, 08:02 PM   #1
michael.glenn.williams
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Rep: Reputation: Disabled
Passing variables between bash and google docs


I have a similar need to this that cannot be solved by using only bash. I need to update a cell on a Google sheet from bash. I also need to fetch/wget/curl a cell from a sheet into a bash variable. Is the only way to do this with the clasp command line tool from bash? If someone could provide a command within bash that sets a bash variable to the value of a cell in a sheet that would be perfect. Thank you!

Last edited by astrogeek; 09-02-2021 at 12:29 PM. Reason: Added link to referenced thread, separated to own thread
 
Old 09-02-2021, 11:04 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,783
Blog Entries: 11

Rep: Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383
Quote:
Originally Posted by michael.glenn.williams View Post
I have a similar need that cannot be solved by using only bash. I need to update a cell on a Google sheet from bash. I also need to fetch/wget/curl a cell from a sheet into a bash variable. Is the only way to do this with the clasp command line tool from bash? If someone could provide a command within bash that sets a bash variable to the value of a cell in a sheet that would be perfect. Thank you!
I think it would be best if you started your won thread with a useful problem description. Read the first 2 non-covid links in my signature for hints.

Generally speaking: Google Docs is full on javascript, command line downloaders like curl or wget won't help you get at the actual document.
Command line javascript engines exist, been a while for me, phantomjs comes to mind, or just your browser in headless mode.
So that's just for the fetching.

How to massage the doc with bash, no idea. Same answer as rtmistler's still applies I guess.

Bash does not have a command line tool named clasp. Could be some 3rd party CLI utility?

edit: searching my package manager for "google docs" gives a few results, one of them looks useful: gdatafs

Last edited by ondoho; 09-02-2021 at 11:06 AM.
 
Old 09-02-2021, 12:32 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,715
Blog Entries: 11

Rep: Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747
Welcome to LQ and the Programming forum!

Your question is complete within itself and more suitable as its own thread and has been moved accordingly. A link to the originally referenced thread has been inserted.
 
Old 09-03-2021, 12:22 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,895

Rep: Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613Reputation: 2613
As mentioned by ondoho, there's a lot more to it, so bash is prob not the lang to use.

Are you averse to using Perl?
Perl has a lot(!) of interfaces into specialist tools like google spreadsheets and in fact here's a module to do what you need https://metacpan.org/pod/Net::Google::Spreadsheets
 
Old 09-03-2021, 01:26 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,854

Rep: Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692
if I understand well this is the official documentation: https://developers.google.com/sheets...te#apps-script
and you will find some examples on the bottom of that page.
 
Old 09-03-2021, 02:44 PM   #6
michael.glenn.williams
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
I could use the proper way to access the Google spreadsheet from bash as well.
Although @Entropy1024 suggested an alternative, the spirit of the post is to
access Google sheets from bash. There is now the Sheets API :
https://developers.google.com/sheets/api/guides/values
and the Google Apps scripts:
https://developers.google.com/sheets...rt/apps-script
but nothing directly from CLI as it seemed there was with curl or wget back in the day.
 
Old 09-03-2021, 03:01 PM   #7
maw_walker
Member
 
Registered: Jul 2021
Location: US
Distribution: FreeBSD, Kali
Posts: 77

Rep: Reputation: Disabled
If I had to guess, authentication would be a problem from bash but I've not done this so can't speak to it exactly. Google uses oauth2 for authentication I believe. No idea if helpful but may be: https://developers.google.com/identity/protocols/oauth2
 
Old 09-04-2021, 12:20 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,783
Blog Entries: 11

Rep: Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383
Quote:
Originally Posted by michael.glenn.williams View Post
I could use the proper way to access the Google spreadsheet from bash as well.
Please define "from bash". I can wrap any program in a short shell script and run it "from bash", but then there's no real need to use bash at all (other than maybe wrap together a few separate commands).

Quote:
the spirit of the post is to access Google sheets from bash. There is now the Sheets API :
https://developers.google.com/sheets/api/guides/values
and the Google Apps scripts:
https://developers.google.com/sheets...rt/apps-script
Looking at these links, there's nothing that suggests bash, or even any sort of Linux command line interface.
Maybe you confuse usage of the word "script", but that's not bash or Linux CLI at all. AFAICS, it's javascript but I might be wrong (extension ".gs" - probably stands for google script, lol).

Quote:
but nothing directly from CLI as it seemed there was with curl or wget back in the day.
As I wrote before, there's no way curl or wget was ever an option with Google Docs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing values from BASH to Google Docs and reading the result Entropy1024 Programming 1 04-05-2019 01:50 PM
LXer: Have you heard of ONLYOFFICE? Itís like Google Docs, only itís not from Google Ö and you might LXer Syndicated Linux News 1 04-04-2015 11:47 PM
Bash Script - Passing command string between variables Devcon Programming 13 01-10-2011 10:13 AM
jdk-6u10-docs.zip jdk-6u10-docs-ja.zip CJohnsonK General 1 08-15-2010 09:38 PM
Passing SSI variables between pages dubya Programming 2 07-05-2005 02:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration