-1

I've written a Bash script that's meant to delete a file then run sqlite3. It runs fine in my mingw64 Bash on Windows, but fails in Bash on macOS.

My script comes with its own copy of sqlite3 in the same directory as the script.

rm -f Input.sqlite
cat SqliteCommands.txt | sqlite3

Output:

compy:program me$ ./Run-Bash.sh
: command not found 2: sqlite3
cat: SqliteCommands.txt: No such file or directory

I remembered that to run a program in the current directory you need to prefix it with ./, so I changed it to:

cat SqliteCommands.txt | ./sqlite3

...which weirdly gets me this error output (verbatim). I don't know why it removed the "sql" part of the file name, that's weird.

: No such file or directorylite3
cat: SqliteCommands.txt: No such file or directory

As macOS comes with its own copy of sqlite3 I changed it to use the full path, but as macOS comes with an older version it means I had to change my SqliteCommands.txt to be compatible which isn't ideal.

cat SqliteCommands.txt | /usr/bin/sqlite3

So how can I pipe to an executable in the same directory as the script?

Dai
  • 141,631
  • 28
  • 261
  • 374

1 Answers1

-2

I am not sure, but try this:

sqlite3 "$(cat SqliteCommands.txt)"

or

cat SqliteCommands.txt | xargs -I {} sqlite3 {}
fairisle
  • 111
  • 1
  • 2