No such file or directory when exporting files using bash script

998 views Asked by At

I am working on a bash script which iterates over mdb files and exports them to a csv.

Here is my code:

#!/bin/bash

YEAR="2001/"
INFOLDER="/local/data/datasets/Convergence/"
OUTFOLDER="~/Workspaces/Ventilator_Repository/dataset/csv/"
for f in "$INFOLDER$YEAR*.mdb";
do
    absname=$INFOLDER$YEAR$(basename $f)
    echo "input file: $absname"
    streamingFile="$OUTFOLDER$YEAR$(basename $f)_streaming.csv"
    echo "output file: $streamingFile"
    streamcommand="mdb-export -d , $absname STREAMING > ${streamingFile}"
    echo "command: $streamcommand"
    mdb-export "-d , " $absname " STREAMING" > $streamingFile
done

However, I am getting this error:

input file: /local/data/datasets/Convergence/2001/14a_25Sep2001_102404.mdb

output file: ~/Workspaces/Ventilator_Repository/dataset/csv/2001/14a_25Sep2001_102404.mdb_streaming.csv

command: mdb-export -d , /local/data/datasets/Convergence/2001/14a_25Sep2001_102404.mdb STREAMING > ~/Workspaces/Ventilator_Repository/dataset/csv/2001/14a_25Sep2001_102404.mdb_streaming.csv

However, I get the following error:

line 14: ~/Workspaces/Ventilator_Repository/dataset/csv/2001/14a_25Sep2001_102404.mdb_streaming.csv: No such file or directory

If I run the command in the terminal, the export works fine! I do not know why in the bash script it does not work.

I am using mdb-tools to export mdb MS Access files into csv and my machine runs on Ubuntu 16.04.

0

There are 0 answers