If statement Syntax error

Hi

Can you please tell me what is wrong with this line:

  if [ [ "${x}" = "12" ] && [ ! "$F" =~ \.g$ ]]; then

basically i want to check if x = 12 and F (Filename) end with 'g'. But it is throwing syntax error.

Drop the first square bracket and add one to the second test.

1 Like

You mean to say like this : if [ "${ptype}" = "sql" && [[ ! "$F" =~ \.sql$ ]]]; then

but this line also gives error

syntax error in conditional expression
syntax error near `;'
if [ "${ptype}" = "sql" && [[ ! "$F" =~ \.sql$ ]]]; then'
 if [ "${ptype}" = "sql" ] && [[ ! "$F" =~ \.sql$ ]]; then
1 Like
if [ ${x} -eq 12 ] && [ $(echo "$f" | grep -Ec ".sql$") -eq 0 ];
1 Like

In this way the test is true only if ptype="sql" and F ends with "sql":

if [[ "${ptype}" = "sql" ]] && [[ "$F" =~ \.sql$ ]]; then

It worked . Thank You

if [[ "$x" -eq 12 && "$F" =~ p$ ]]; then