![]() |
#1 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Oct 2010
Device: iPad / Kindle DX
|
Quoting variables containing options in CLI
I'm on Max OSX. I want to use a bash shell script to fill the 'authors' field and a 'translator' custom field.
This works perfectly: Code:
#!/bin/bash id=10030 calibredb set_metadata -f "authors:John Doe" -f "#translator:Jane Doe" $id Code:
#!/bin/bash id=10030 a='-f "authors:John Doe"' t='-f "#translator:Jane Doe"' echo calibredb set_metadata $a $t $id calibredb set_metadata $a $t $id You must specify a record id as the first argument. If I put the variables in the last line inside double quotes, the error becomes: "authors is not a known field This gives me idea to do the following, which does work, despite the fact that what echo returns now fails when pasted in a new shell window. Code:
#!/bin/bash id=10030 a='-fauthors:John Doe' t='-f#translator:Jane Doe' echo calibredb set_metadata "$a" "$t" "$id" calibredb set_metadata "$a" "$t" "$id" I realize that the main issue here is my confusion about quotes and expansions in bash, but since I am trying to teach myself scripting mainly to use with Calibre, I thought that someone in this forum will enlighten me . My practical goal is to use set_metadata in a script with only one variable for all the options - I want only one because my script builds it progressively, through loops and conditionals. However, any general description and explanation of the phenomena I'm encountering here would be immensely valued. Thanks in advance. W. |
![]() |
![]() |
![]() |
#2 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Oct 2010
Device: iPad / Kindle DX
|
To be even more specific, this works;
Code:
a="authors:John Doe" calibredb set_metadata -f "$a" 10030 Code:
a="-f authors:John Doe" calibredb set_metadata "$a" 10030 Code:
a="-fauthors:John Doe" calibredb set_metadata "$a" 10030 Thank in advance. W. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,185
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
What you need to understand as far as calibredb is concerned is that you need to pass either of the two following forms of command line arguments to it
*One* argument of the form -fwhatever or *Two* arguments of the form -f whatever These are exactly equivalent. Now remember that bash splits command line arguments at spaces, unless you surround them in quotes, in which case they become one argument. With that in mind you should be able to understand the results you are getting. |
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Passing the entire command as one string to `eval` will allow it to be interpreted the way you would've expected. Of course, "eval is evil".
![]() Code:
#!/bin/bash id=10030 a='-f "authors:John Doe"' t='-f "#translator:Jane Doe"' eval calibredb set_metadata $a $t $id Last edited by eschwartz; 08-06-2015 at 10:21 PM. |
![]() |
![]() |
![]() |
Tags |
bash, cli, mac, quotes, set_metadata |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Suggestion: Book level variables | phossler | Editor | 15 | 02-17-2014 11:26 AM |
Epub capable ebook reader for win7 with commandline options (CLI) | Togg | Windows Devices | 1 | 04-24-2013 04:07 PM |
Regex capturing variables | Lonas | Sigil | 9 | 08-14-2010 03:05 PM |
Noob: just getting my head around all the variables | KAM | Sony Reader | 16 | 02-04-2009 06:16 PM |