PDA

View Full Version : [SOLVED] Shell scripts work in Manjaro but not Ubuntu



raysa
July 25th, 2018, 02:53 PM
I have these two little scripts in a directory where I place music files in abc format, intending to convert them into pdf files of the same name.
They work perfectly on a laptop whose OS is Manjaro linux, but they don't work on my main desktop which is Ubuntu.
What needs to change to make them work in the Ubuntu setting?

The first script is called 'abc2pdfbatch' and it calls the second one called 'abc2pdf'

#!/bin/bash

find . -maxdepth 1 -type f -name "$1" \
-exec ./abc2pdf {} \; \

mkdir -p pdf_a5

find . -maxdepth 1 -type f -name "*.pdf" \
-exec mv -v {} pdf_a5/{} \; \

#!/bin/bash
set -euo pipefail
abcm2ps "$1"
ps2pdfwr -sPAPERSIZE=a5 Out.ps "${1/%.abc/.pdf}"

Please note I'm not a programmer and don't really understand these scripts, which I adopted from elsewhere.
Thanks.

Claus7
July 25th, 2018, 03:28 PM
Hello,

you should make both of them executable:
1) open a terminal and navigate to the folder that you have placed those 2 scripts then
2) chmod 755 abc2pdfbatch abc2pdf

I tested them in my ubu box and they do work.

Regards!

Olav
July 25th, 2018, 03:33 PM
In addition the packages abcm2ps and ghostscript (for ps2pdf) must also be installed.

raysa
July 25th, 2018, 04:34 PM
Many thanks, both. Followed/enacted all your points ... and checked my own typing when asking the first script to run (Doh!) ... and now all is working as it should.
Thanks again.

Claus7
August 15th, 2018, 04:50 PM
Hello,


Many thanks, both. Followed/enacted all your points ... and checked my own typing when asking the first script to run (Doh!) ... and now all is working as it should.
Thanks again.

nice!

I will make an attempt to explain what the scripts and their corresponding commands do:

1st script


find . -maxdepth 1 -type f -name "$1" \
-exec ./abc2pdf {} \; \




find
we try to search for


-type f
files


.
having as a starting point the current folder (dot could be omitted)


-maxdepth 1
descending at most 1 level of directories below the starting-point


-name "$1"
where the filename should match the first argument passed to the script [the double quotes expand the variable 1, since they are keeping the symbol, $, as a special character]


\
the command continues in the next line


-exec
execute the part that follows exec, taking as arguments the result from find


./abc2pdf
convert abc to pdf using the 2nd script


{}
using as input the filename found before


\;
terminate exec command


\
not needed





mkdir -p pdf_a5




mkdir -p pdf_a5
create parent directory pdf_a5 and report no error if it exists




find . -maxdepth 1 -type f -name "*.pdf" \
-exec mv -v {} pdf_a5/{} \; \




find . -maxdepth 1 -type f -name "*.pdf" \
the same as previous, yet now find all filenames that have the extension pdf


-exec mv -v {} pdf_a5/{} \; \
and move them under the directory pdf_a5



2nd script



set -euo pipefail



-e
cause the bash script to exit immediately when a command fails


-u
cause the bash shell to treat unset variables as an error and exit immediately



-o pipefail
the bash shell normally only looks at the exit code of the last command of a pipeline;this particular option sets the exit code of a pipeline to that of the rightmost command to exit


abcm2ps "$1"
convert abc music files to postscript files


ps2pdfwr
convert postscript files to pdf


-sPAPERSIZE=a5
with paper size a5


Out.ps
the name of the postscript file that will be converted to pdf is Out.ps


"${1/%.abc/.pdf}"
the name of the pdf file created will be that of the corresponding abc file, yet with the extention pdf - the % can be omitted and written as ${1/.abc/.pdf}, where the name that is represented from 1, its .abc part, will be substituted with the .pdf part



In order to test it in one sample file line-by-line the command:

set -- sample.abc
would help since if we issue afterwards the command:

echo $1
the result will be:

sample.abc

Just a notice: some abc files might give warnings. If they do so, then the "set -euo pipefail" option will make the scripts to exit, and the conversions won't work. For that reason it is adviced to remove that option by adding a # in front of that line of the 2nd script:
#set -euo pipefail

Regards!