0

I have this code:

ColumnInformation=`sqlite3 $database "PRAGMA table_info($table);"`

and it works perfect, but I need add the if statement:

if [$table != "Order"]; then
    ColumnInformation=`sqlite3 $database "PRAGMA table_info($table);"`
else
    ColumnInformation=`sqlite3 $database "PRAGMA table_info('Order');"`
fi

it throws command not found error. Could you tell me why ?

best, Tomek

1
  • 1
    You need spaces around [ and ]. Commented Jan 10, 2014 at 14:56

1 Answer 1

2

Could be lack of space either side of [ and ] and you need to use "backticks" to get the output from a sub-command:

if [ $table != "Order" ]; then
    ColumnInformation=`sqlite3 $database "PRAGMA table_info('$table');"`
else
    ColumnInformation=`sqlite3 $database "PRAGMA table_info('Order');"`
fi

However the test appears to be pointless anyway as $table is "Order" in the second case anyway. Also note that you were missing single-quotes around $table in the first case.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.