Goal:
I have a sneaking suspicion that I'm globbing incorrectly due to not being able to find a satisfactory explanation with multiple clear examples of advanced string-and-var mixing.
The operation I am trying to perform is on the last line, and the goal is to output the outputdirectory + filebasename + outputextension. Unfortunately, there are too many variables, and despite reading multiple manuals, I feel certain I am making mistakes.
#!/bin/bash
echo Input directory name like ./path/to:
read -r varin
echo Input directory name like ./path/to:
read -r varout
if [ ! -d "${varout}" ]; then
mkdir -p "${varout}";
fi
for file in ${varin}; do pconvert -i "${file}" -o "${varout}"/"${file%%.*}".txt; done
error:
File './inputs/outputs/*/.txt' already exists. Overwrite ? [y/N] ^C
Unexpected behavior:
- I have to write
./inputs/*
instead of./inputs
, and this is unexpected. I expected bash to look for a directory then loop through the files in that directory: this is fine, but it shows that I am not comprehending the code. - Presuming I type
./inputs/outputs/*
, this script tries to create./inputs/outputs/*.txt
on each iteration rather than./inputs/outputs/inputname.txt
. The goal in the last operation on line 15 is to scrub the directory, scrub the extension, and use the new path + basename + newextension. Kind of the blind leading the blind, but I feel like this can only have something to do with my use of quotation marks?
Resources I've used:
According to this link, I should probably do something like this:
convertdoc -i "$'{file}'" --pdfconvert -o "$'{outputDir}'/$'{file%%.*}'.odf
But I am getting mixed opinions from friends. So far, I've been told to use no trailing quote, to only use semiquotes, to use quotes both prior to and after the dollar sign, and to be pipe down, to mention a few.
Sample inputs:
$HOME/pdfdl/ardvarks.pdf
$HOME/pdfdl/ants.pdf
$HOME/pdfdl/canines.pdf
$HOME/pdfdl/cats.tmp.pdf