-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsqlite3
More file actions
executable file
·33 lines (28 loc) · 996 Bytes
/
sqlite3
File metadata and controls
executable file
·33 lines (28 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
. /opt/cs50/lib/cli
# If data is coming from stdin (pipe or redirection)
if [[ -p /dev/stdin || ! -t 0 ]]; then
/usr/local/bin/sqlite3 -nullvalue NULL -table "$@" < /dev/stdin
exit $?
fi
# If no command-line argument
if [[ $# -eq 0 ]]; then
if ! _sure "Are you sure you want to run \`sqlite3\` without a command-line argument (e.g., the filename of a database)?"; then
exit 1
fi
# If one command-line argument
elif [[ $# -eq 1 ]] && [[ ! "$1" =~ ^- ]]; then
if [[ ! -f "$1" ]]; then
if [[ ! "$1" =~ \.db$ ]]; then
if ! _sure "Are you sure you want to create \`$1\`? SQLite filenames usually end in \`.db\`."; then
exit 1
fi
else
if ! _sure "Are you sure you want to create \`$1\`?"; then
exit 1
fi
fi
/usr/local/bin/sqlite3 "$@" "VACUUM;" # https://stackoverflow.com/a/51455470
fi
fi
/usr/local/bin/sqlite3 -nullvalue NULL -table "$@"