0

I am receiving a query via a configuration file in unix, for ex. Config file content will be in the format:

Table_name|query

ABC|select ABC.A,ABC.B from PQR left join (select * from ABC) on ABC.pk=PQR.pk

I am trying to process query part as below :

    while read line in config_file
    do
        query=`echo $line|awk -F "|" '{print $1}'`
        result=hive -e "$query"
        ...

However the '*' in query variable is getting expanded to the listing of files in the current directory

Could you please help how to escape the * character, i searched for the solution but could not find one.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
  • have you tried the methods in https://stackoverflow.com/a/11456496/8953000 ? – BANJOSA Jan 24 '20 at 12:16
  • Quote the `$line` variable: `echo "$line"`. For further information see for example [When is double-quoting necessary?](https://unix.stackexchange.com/a/68748/65304) – steeldriver Jan 24 '20 at 12:16
  • It might generally be usefull to know on which OS exactly you are and which shell you are using. – Thorian93 Jan 24 '20 at 12:21
  • See also [Understanding "IFS= read -r line"](//unix.stackexchange.com/q/209123) and [Why is printf better than echo?](//unix.stackexchange.com/q/65803). Note here you could do `query=${line%%'|'*}` – Stéphane Chazelas Jan 24 '20 at 12:35
  • Thanks for reply " resloved the issue – Saket Mankar Jan 30 '20 at 12:13

1 Answers1

0

Hi Saket Mankar and welcome to the community!

You would need to enclose the $line variable with double quotes: "$line".

That should solve your situation.

Thorian93
  • 733
  • 2
  • 6
  • 17