I've got this script

while [ -e $name.$idx ]; do 
    idx=`expr $idx + 1`; 
while [ $idx -gt 1 ]; do 
    nidx=`expr $idx - 1`; mv $name.$nidx $name.$idx; idx=$nidx; 
[ ! -e $name ] || mv $name $name.1
sqlite3 test.sqlite < /path/to/db_schema.sh

and db_schema.sh

create table objects(id integer primary key autoincrement, name text, crc integer not null);
create index objects_idx on objects(crc);

create table symbols(id integer primary key autoincrement, name text, crc integer not null);
create index symbols_idx on symbols(crc);

create table provides(object_id integer not null, symbol_id integer not null);
create index provides_idx_sym on provides(symbol_id);
create index provides_idx_obj on provides(object_id);
create unique index provides_idx_key on provides(object_id, symbol_id);

create table depends(object_id integer not null, symbol_id integer not null);
create index depends_idx_sym on depends(symbol_id);
create index depends_idx_obj on depends(object_id);
create unique index depends_idx_key on depends(object_id,symbol_id);

This did work until today. What I tried so far

  1. hard-coding the path to db_schema.sh
  2. setting a variable to the file ($DB_SCHEMA_VAR)
  3. setting the path as variable but hardcoding the file ($PATH_TO_FILE/db_schema.sh)
  4. changing the folder the file is in and the three above

I also checked if the file is executable (it is), wrote a little line testing if the file is present

if [ -f db_schema.sh ] ; then .... 

before the database gets created. The test shows db_schema.sh is there, but as soon as db_schema.sh gets called, it suddenly is no longer present.

And here the log output as asked for by Barefoot IO

+ DB_INIT (this is because i call it as a function and it is not a stand-alone script)
+ cd DB_wdsfasdfg
+ name=test.sqlite
+ idx=1
+ '[' -e test.sqlite.1 ']'
+ '[' 1 -gt 1 ']'
+ '[' '!' -e test.sqlite ']'
+ sqlite3 test.sqlite
./files/functions/init_db.sh: line 22: ./files/functions/db_schema.sh: No such file or directory
  • What's the error? There's a few things happening on your script -- narrow it down to the problem area.
    – Jeff Schaller
    Commented Feb 20, 2016 at 20:54
  • It would be helpful if you traced the script and shared the log: bash -x scriptfile 2> trace.log. Commented Feb 20, 2016 at 21:16
  • gonna add this, it may take a moment
    – chris
    Commented Feb 20, 2016 at 21:17

1 Answer 1


I assume that init_db.sh and db_schema.sh are in the same directory.

The combination of cd and a file name that's relative to the current working directory, ./files/functions/db_schema.sh, suggests that db_schema.sh cannot be found because the current working directory is no longer what it was at the time that ./files/functions/init_db.sh was invoked.

If the script was in the correct directory before cd DB_wdsfasdfg, then perhaps it will suffice to return to that directory, using cd -, before invoking sqlite3.

Alternatively, you can specify an absolute pathname -- a pathname beginning with a / -- which is independent of the current directory.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .