Running basexclient Command From a Bash Script

Sunday, 22 March 2015 · 5 messages · last reply 24 Mar 2015
EK
Eliot Kimber22 Mar 2015 18:31 #
I'm trying to implement agit commit hook that updates a BaseX database with updates committed to the git repo (the BaseX database is being used for search and link management). My script is here: https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/develop/ post-commit The important code is: ---------- addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM" # echo "Adding/Updating files:" for line in ${addOrUpdate}; do cmd="basexclient -c \"OPEN ${basexDatabase};REPLACE ${line} ${topDir}/${line};EXIT\" ${basexOptions}" echo "Running cmd: ${cmd}" $($cmd) done --------- When I run the script I'm getting this response: Contrext01:docs ekimber$ ../../dita-for-small-teams/commit-hooks/git/post-commit Running cmd: basexclient -c "OPEN sample-project;REPLACE docs/topic-01.dita /Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dita;E XIT" -U admin -P admin -p 1984 -n localhost Stopped at , 1/6: Unknown command: "OPEN. Did you mean 'OPEN'? Contrext01:docs ekimber$ If I copy the command from the message and run it directly from the command line it works as expected. There must be some subtlety of using base in this context but my bash fu is weak and I have no idea what I'm doing wrong--I can't see any obvious user error but there must be one. Can anyone tell me what my bash scripting mistake is? Is there a better way to do this sort of scripted interaction with basex? It didn't appear that BaseX scripts provided a way to take parameters--if they could then I'd just call a .bxs script with the relevant parameters. Short of generating the script and then running it, I couldn't think of a simpler way to do what I want that just using the -c option on the basexclient command. Thanks, Eliot ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
CD
Charles Duffy22 Mar 2015 18:51 #
[Eliot, apologies for the duplicate mail -- I just realized that my initial replies weren't CC'd to the list. Note that this fixes a bug in the last version I sent you privately; please use it in preference]. --- Please see BashFAQ #50: http://mywiki.wooledge.org/BashFAQ/050; argument lists should be handled as arrays, not strings. ...also, see BashFAQ #1, http://mywiki.wooledge.org/BashFAQ/001, and (for the same reason) http://mywiki.wooledge.org/DontReadLinesWithFor A better version of this script might look like: #!/bin/bash # ^-- MUST NOT BE /bin/sh
addOrUpdate() { git diff HEAD^ HEAD --name-only --diff-filter=AM; }
basexOptions=( -U admin -P admin -p 1984 -n localhost )
while read -r line; do cmd=( basexclient -c "OPEN $basexDatabase; REPLACE $line $topDir/$line; EXIT" "${basexOptions[@]}" ) printf 'Running: '; printf '%q ' "${cmd[@]}"; printf '\n' "${cmd[@]}" done < <(addOrUpdate)
Quoted text · Eliot Kimber · 65 lines
On Sun, Mar 22, 2015 at 11:31 AM, Eliot Kimber <ekimber at contrext.com> wrote: > I'm trying to implement agit commit hook that updates a BaseX database > with updates committed to the git repo (the BaseX database is being used > for search and link management). > > My script is here: > > https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/develop/ > post-commit > > The important code is: > > ---------- > addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM" > > # echo "Adding/Updating files:" > for line in `${addOrUpdate}`; do > cmd="basexclient -c \"OPEN ${basexDatabase};REPLACE ${line} > ${topDir}/${line};EXIT\" ${basexOptions}" > echo "Running cmd: ${cmd}" > $($cmd) > done > > --------- > > When I run the script I'm getting this response: > > Contrext01:docs ekimber$ > ../../dita-for-small-teams/commit-hooks/git/post-commit > Running cmd: basexclient -c "OPEN sample-project;REPLACE > docs/topic-01.dita > /Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dita;E > XIT" -U admin -P admin -p 1984 -n localhost > Stopped at , 1/6: > Unknown command: "OPEN. Did you mean 'OPEN'? > Contrext01:docs ekimber$ > > If I copy the command from the message and run it directly from the > command line it works as expected. > > > There must be some subtlety of using base in this context but my bash fu > is weak and I have no idea what I'm doing wrong--I can't see any obvious > user error but there must be one. > > Can anyone tell me what my bash scripting mistake is? > > Is there a better way to do this sort of scripted interaction with basex? > It didn't appear that BaseX scripts provided a way to take parameters--if > they could then I'd just call a .bxs script with the relevant parameters. > Short of generating the script and then running it, I couldn't think of a > simpler way to do what I want that just using the -c option on the > basexclient command. > > Thanks, > > Eliot > > ————— > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > >
EK
Eliot Kimber22 Mar 2015 22:44 #
Cool, Thanks for all the info. I knew it was due to my very weak understanding of bash scripting. The improved script you suggested worked. I'll do the reading necessary to understand *why* it works, but that gets me over the immediate hurdle. Cheers, E. ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
Quoted text · Charles Duffy · 104 lines
On 3/22/15, 11:51 AM, "Charles Duffy" <charles at dyfis.net> wrote: >[Eliot, apologies for the duplicate mail -- I just realized that my >initial replies weren't CC'd to the list. Note that this fixes a bug >in the last version I sent you privately; please use it in >preference]. > >--- > >Please see BashFAQ #50: http://mywiki.wooledge.org/BashFAQ/050; >argument lists should be handled as arrays, not strings. > >...also, see BashFAQ #1, http://mywiki.wooledge.org/BashFAQ/001, and >(for the same reason) http://mywiki.wooledge.org/DontReadLinesWithFor > >A better version of this script might look like: > >#!/bin/bash ># ^-- MUST NOT BE /bin/sh > >addOrUpdate() { git diff HEAD^ HEAD --name-only --diff-filter=AM; } >basexOptions=( -U admin -P admin -p 1984 -n localhost ) > >while read -r line; do > cmd=( basexclient -c "OPEN $basexDatabase; REPLACE $line >$topDir/$line; EXIT" "${basexOptions[@]}" ) > printf 'Running: '; printf '%q ' "${cmd[@]}"; printf '\n' > "${cmd[@]}" >done < <(addOrUpdate) > >On Sun, Mar 22, 2015 at 11:31 AM, Eliot Kimber <ekimber at contrext.com> >wrote: >> I'm trying to implement agit commit hook that updates a BaseX database >> with updates committed to the git repo (the BaseX database is being used >> for search and link management). >> >> My script is here: >> >> >>https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/develo >>p/ >> post-commit >> >> The important code is: >> >> ---------- >> addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM" >> >> # echo "Adding/Updating files:" >> for line in `${addOrUpdate}`; do >> cmd="basexclient -c \"OPEN ${basexDatabase};REPLACE ${line} >> ${topDir}/${line};EXIT\" ${basexOptions}" >> echo "Running cmd: ${cmd}" >> $($cmd) >> done >> >> --------- >> >> When I run the script I'm getting this response: >> >> Contrext01:docs ekimber$ >> ../../dita-for-small-teams/commit-hooks/git/post-commit >> Running cmd: basexclient -c "OPEN sample-project;REPLACE >> docs/topic-01.dita >> >>/Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dita >>;E >> XIT" -U admin -P admin -p 1984 -n localhost >> Stopped at , 1/6: >> Unknown command: "OPEN. Did you mean 'OPEN'? >> Contrext01:docs ekimber$ >> >> If I copy the command from the message and run it directly from the >> command line it works as expected. >> >> >> There must be some subtlety of using base in this context but my bash fu >> is weak and I have no idea what I'm doing wrong--I can't see any obvious >> user error but there must be one. >> >> Can anyone tell me what my bash scripting mistake is? >> >> Is there a better way to do this sort of scripted interaction with >>basex? >> It didn't appear that BaseX scripts provided a way to take >>parameters--if >> they could then I'd just call a .bxs script with the relevant >>parameters. >> Short of generating the script and then running it, I couldn't think of >>a >> simpler way to do what I want that just using the -c option on the >> basexclient command. >> >> Thanks, >> >> Eliot >> >> ————— >> Eliot Kimber, Owner >> Contrext, LLC >> http://contrext.com >> >> >> >
EK
Eliot Kimber22 Mar 2015 23:02 #
Small hick-up: the script works under OS X (and I'll assume under Linux) but not in the git shell under Windows. I should be able to use a separate batch script for Windows but it would be easiest if a single script was cross platform. Hmph. Cheers, E. ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
Quoted text · Eliot Kimber · 134 lines
On 3/22/15, 3:44 PM, "Eliot Kimber" <ekimber at contrext.com> wrote: >Cool, > >Thanks for all the info. I knew it was due to my very weak understanding >of bash scripting. > >The improved script you suggested worked. I'll do the reading necessary to >understand *why* >it works, but that gets me over the immediate hurdle. > >Cheers, > >E. >————— >Eliot Kimber, Owner >Contrext, LLC >http://contrext.com > > > > >On 3/22/15, 11:51 AM, "Charles Duffy" <charles at dyfis.net> wrote: > >>[Eliot, apologies for the duplicate mail -- I just realized that my >>initial replies weren't CC'd to the list. Note that this fixes a bug >>in the last version I sent you privately; please use it in >>preference]. >> >>--- >> >>Please see BashFAQ #50: http://mywiki.wooledge.org/BashFAQ/050; >>argument lists should be handled as arrays, not strings. >> >>...also, see BashFAQ #1, http://mywiki.wooledge.org/BashFAQ/001, and >>(for the same reason) http://mywiki.wooledge.org/DontReadLinesWithFor >> >>A better version of this script might look like: >> >>#!/bin/bash >># ^-- MUST NOT BE /bin/sh >> >>addOrUpdate() { git diff HEAD^ HEAD --name-only --diff-filter=AM; } >>basexOptions=( -U admin -P admin -p 1984 -n localhost ) >> >>while read -r line; do >> cmd=( basexclient -c "OPEN $basexDatabase; REPLACE $line >>$topDir/$line; EXIT" "${basexOptions[@]}" ) >> printf 'Running: '; printf '%q ' "${cmd[@]}"; printf '\n' >> "${cmd[@]}" >>done < <(addOrUpdate) >> >>On Sun, Mar 22, 2015 at 11:31 AM, Eliot Kimber <ekimber at contrext.com> >>wrote: >>> I'm trying to implement agit commit hook that updates a BaseX database >>> with updates committed to the git repo (the BaseX database is being >>>used >>> for search and link management). >>> >>> My script is here: >>> >>> >>>https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/devel >>>o >>>p/ >>> post-commit >>> >>> The important code is: >>> >>> ---------- >>> addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM" >>> >>> # echo "Adding/Updating files:" >>> for line in `${addOrUpdate}`; do >>> cmd="basexclient -c \"OPEN ${basexDatabase};REPLACE ${line} >>> ${topDir}/${line};EXIT\" ${basexOptions}" >>> echo "Running cmd: ${cmd}" >>> $($cmd) >>> done >>> >>> --------- >>> >>> When I run the script I'm getting this response: >>> >>> Contrext01:docs ekimber$ >>> ../../dita-for-small-teams/commit-hooks/git/post-commit >>> Running cmd: basexclient -c "OPEN sample-project;REPLACE >>> docs/topic-01.dita >>> >>>/Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dit >>>a >>>;E >>> XIT" -U admin -P admin -p 1984 -n localhost >>> Stopped at , 1/6: >>> Unknown command: "OPEN. Did you mean 'OPEN'? >>> Contrext01:docs ekimber$ >>> >>> If I copy the command from the message and run it directly from the >>> command line it works as expected. >>> >>> >>> There must be some subtlety of using base in this context but my bash >>>fu >>> is weak and I have no idea what I'm doing wrong--I can't see any >>>obvious >>> user error but there must be one. >>> >>> Can anyone tell me what my bash scripting mistake is? >>> >>> Is there a better way to do this sort of scripted interaction with >>>basex? >>> It didn't appear that BaseX scripts provided a way to take >>>parameters--if >>> they could then I'd just call a .bxs script with the relevant >>>parameters. >>> Short of generating the script and then running it, I couldn't think of >>>a >>> simpler way to do what I want that just using the -c option on the >>> basexclient command. >>> >>> Thanks, >>> >>> Eliot >>> >>> ————— >>> Eliot Kimber, Owner >>> Contrext, LLC >>> http://contrext.com >>> >>> >>> >> > > >
CG
Christian Grün24 Mar 2015 16:03 #
Hi Eliot, Thanks for the link to your BaseX script. If you can create a temporary file with the paths to all updated git in the first step, you could use an XQuery script to replace all files in the database: _ basex call __________________ $ basex -bpwd=$topDir -bdb=$basexDatabase -bfile=files.txt replace-files.xq _ replace-files.xq ______________
  declare variable $dir external;
  declare variable $db external;
  declare variable $file external;
  for $line in unparsed-text-lines($file)
  return db:replace($db, $line, $dir || $line)
____________________________
Hope this helps, Christian
Quoted text · Eliot Kimber · 156 lines
On Sun, Mar 22, 2015 at 10:02 PM, Eliot Kimber <ekimber at contrext.com> wrote: > Small hick-up: the script works under OS X (and I'll assume under Linux) > but not in the git shell under Windows. I should be able to use a separate > batch script for Windows but it would be easiest if a single script was > cross platform. > > Hmph. > > Cheers, > > E. > ————— > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > > > > On 3/22/15, 3:44 PM, "Eliot Kimber" <ekimber at contrext.com> wrote: > >>Cool, >> >>Thanks for all the info. I knew it was due to my very weak understanding >>of bash scripting. >> >>The improved script you suggested worked. I'll do the reading necessary to >>understand *why* >>it works, but that gets me over the immediate hurdle. >> >>Cheers, >> >>E. >>————— >>Eliot Kimber, Owner >>Contrext, LLC >>http://contrext.com >> >> >> >> >>On 3/22/15, 11:51 AM, "Charles Duffy" <charles at dyfis.net> wrote: >> >>>[Eliot, apologies for the duplicate mail -- I just realized that my >>>initial replies weren't CC'd to the list. Note that this fixes a bug >>>in the last version I sent you privately; please use it in >>>preference]. >>> >>>--- >>> >>>Please see BashFAQ #50: http://mywiki.wooledge.org/BashFAQ/050; >>>argument lists should be handled as arrays, not strings. >>> >>>...also, see BashFAQ #1, http://mywiki.wooledge.org/BashFAQ/001, and >>>(for the same reason) http://mywiki.wooledge.org/DontReadLinesWithFor >>> >>>A better version of this script might look like: >>> >>>#!/bin/bash >>># ^-- MUST NOT BE /bin/sh >>> >>>addOrUpdate() { git diff HEAD^ HEAD --name-only --diff-filter=AM; } >>>basexOptions=( -U admin -P admin -p 1984 -n localhost ) >>> >>>while read -r line; do >>> cmd=( basexclient -c "OPEN $basexDatabase; REPLACE $line >>>$topDir/$line; EXIT" "${basexOptions[@]}" ) >>> printf 'Running: '; printf '%q ' "${cmd[@]}"; printf '\n' >>> "${cmd[@]}" >>>done < <(addOrUpdate) >>> >>>On Sun, Mar 22, 2015 at 11:31 AM, Eliot Kimber <ekimber at contrext.com> >>>wrote: >>>> I'm trying to implement agit commit hook that updates a BaseX database >>>> with updates committed to the git repo (the BaseX database is being >>>>used >>>> for search and link management). >>>> >>>> My script is here: >>>> >>>> >>>>https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/devel >>>>o >>>>p/ >>>> post-commit >>>> >>>> The important code is: >>>> >>>> ---------- >>>> addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM" >>>> >>>> # echo "Adding/Updating files:" >>>> for line in `${addOrUpdate}`; do >>>> cmd="basexclient -c \"OPEN ${basexDatabase};REPLACE ${line} >>>> ${topDir}/${line};EXIT\" ${basexOptions}" >>>> echo "Running cmd: ${cmd}" >>>> $($cmd) >>>> done >>>> >>>> --------- >>>> >>>> When I run the script I'm getting this response: >>>> >>>> Contrext01:docs ekimber$ >>>> ../../dita-for-small-teams/commit-hooks/git/post-commit >>>> Running cmd: basexclient -c "OPEN sample-project;REPLACE >>>> docs/topic-01.dita >>>> >>>>/Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dit >>>>a >>>>;E >>>> XIT" -U admin -P admin -p 1984 -n localhost >>>> Stopped at , 1/6: >>>> Unknown command: "OPEN. Did you mean 'OPEN'? >>>> Contrext01:docs ekimber$ >>>> >>>> If I copy the command from the message and run it directly from the >>>> command line it works as expected. >>>> >>>> >>>> There must be some subtlety of using base in this context but my bash >>>>fu >>>> is weak and I have no idea what I'm doing wrong--I can't see any >>>>obvious >>>> user error but there must be one. >>>> >>>> Can anyone tell me what my bash scripting mistake is? >>>> >>>> Is there a better way to do this sort of scripted interaction with >>>>basex? >>>> It didn't appear that BaseX scripts provided a way to take >>>>parameters--if >>>> they could then I'd just call a .bxs script with the relevant >>>>parameters. >>>> Short of generating the script and then running it, I couldn't think of >>>>a >>>> simpler way to do what I want that just using the -c option on the >>>> basexclient command. >>>> >>>> Thanks, >>>> >>>> Eliot >>>> >>>> ————— >>>> Eliot Kimber, Owner >>>> Contrext, LLC >>>> http://contrext.com >>>> >>>> >>>> >>> >> >> >> > >

⚡Generated with XQuery