I have a bash script that needs the count of records/documents that exist for a given arango collection. This seemed easy enough, I used the following arangosh call:

records=$(docker exec -it arango arangosh --javascript.execute scripts/getCount.js $collection --server.password '')

which then runs the following script:

#!/usr/bin/arangosh --javascript.execute 

var collection = ARGUMENTS[0];
var doc = db[collection];

var c = doc.count();

This appears to work, but when I echo $records I get the correct value but it appears bolded. This leads to other reading issues so I redirected the docker exec call to cat -v and got the following output:


The #### is my record value and it is correct. How do I either properly print the value out of arangosh or out of docker exec? Or is the only path to strip these hidden ansi characters from my value?


I was able to attempt docker exec -it arango arangosh and attempt the command db._collection('my_collection').count() directly. This returned a bolded value which I believe means that it contains the hidden characters (arangosh doesn't have cat defined so I couldn't verify 100%).

With that said I believe the question is, can this be exported in plain text or do I need to sed substitute these characters after my script receives the response?


Still hoping for a better answer but I was able to get what I needed with the following:

imported=`docker exec -it arango arangosh --javascript.execute scripts/getRecords.js $collection --server.password '' | cat -v | sed 's/\(\^\[\[1m\)//g;s/\(\^\[\[0m^M\)//g'`

This simply passed the verbose output from docker to a sed substitution. Considering that for this script I expect the characters to be the same for all collections I am supplying to this script this should do the trick (just very limited).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.