bash - How to set result of command to variable -


i'm trying display line number of first 'string' occurence long string variable , set result other variable.

to display line of first 'string" occurence use:

grep -n -m 1 string filename.csv |cut -f1 -d: 

it works fine. 'string' value array variable , filename.csv switch long string. example:

string[0]='column2'  query="select column1,               column2,               column3          dual" 

and now:

line_number=$(grep -n -m 1 ${string[0]} "$query" |cut -f1 -d:) echo $line_number 

result should : 2

not display: grep: "select column1, column2, column3 dual " no such file or directory what's wrong?

change script :

string[0]='column2'  query="select column1,\n               column2,\n               column3\n          dual"  line_number=$(echo $query | grep -n -m 1 ${string[0]} |cut -f1 -d:) echo $line_number 

and see get.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -