Creating an expression with equal to in shell script

Ravi

I am trying a FOR loop in Linux Shell script to generate a condition to be passed on to a SQL query within the shell script. The following is the portion that is giving error:

    > condition=${primarykey//,/ }
    > echo $condition
      cond1 cond2

    > temp=""

    > for i in $condition
    > do
    >   $temp="${temp}c.${i}\=s.${i} AND "
    > done

I am looking for the following expression to be generated:

    > echo $temp
      c.cond1=s.cond1 AND c.cond2=s.cond2

However, I get the following error:

    ./script.sh: line 28: =c.cond1\=s.cond1 AND : command not found
    ./script.sh: line 28: =c.cond2\=s.cond2 AND : command not found

Could someone help me with the right way to get this expression?

Ignacio Vazquez-Abrams

The $ implies substitution. As in, take the contents of the variable and substitute it into the command line at that point. If you want to assign then you must not substitute.

TL;DR: Remove the dollar sign to the left of the equals sign.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

wildcard in regular expression in shell script

분류에서Dev

call Equal method of Expression

분류에서Dev

Creating a cronjob through script

분류에서Dev

Creating a shortcut or a script in Ubuntu

분류에서Dev

Creating table with python script

분류에서Dev

Call shell script "inline" in another shell script

분류에서Dev

Beep in shell script not working?

분류에서Dev

Add "not" to if statement in shell script

분류에서Dev

Error executing shell script

분류에서Dev

String substitute in Shell script

분류에서Dev

Shell script - text processing

분류에서Dev

Problem with encoding in shell script

분류에서Dev

Breaking loop in shell script

분류에서Dev

Nested If Statements in Shell Script

분류에서Dev

Mount fails in shell script

분류에서Dev

Replacing text in a Shell Script

분류에서Dev

Using find in shell script

분류에서Dev

Creating a very simple upstart script

분류에서Dev

executing shell command using shell script

분류에서Dev

Creating eset object from preprocessed expression matrix?

분류에서Dev

Shell Script to pass arguments to another script

분류에서Dev

Shell script: time and python into a file

분류에서Dev

Hiding Command Messages in a Shell Script

분류에서Dev

Shell script suddently stopped working

분류에서Dev

Run script in a non interactive shell?

분류에서Dev

eval is giving error in shell script

분류에서Dev

Check if connected to a VPN in shell script

분류에서Dev

Need Shell Script to find this pattern

분류에서Dev

Cost of file Operation in Shell Script