Skip to main content
added 4 characters in body; edited tags
Source Link
user3450548
  • 3.1k
  • 13
  • 37
  • 56

I have this shell script:

UNZIP_FOUND=$(dpkg-query -W --showformat='${Status}\n' unzip|grep "install ok installed")
    if [ "" == "$UNZIP_FOUND" ]; then
        echo unzip not found, I will install it
        apt-get --assume-yes install unzip > /dev/null
    fi

However this produces me a sentence each time:

dpkg-query: no packages found matching unzip

Beforebefore running the actual installation step, there's.

Is there a way to get rid of it ?

I need to just assign the value of dkpg-query command inside the UNZIP_FOUND variable but I don't want to echo it.

I read that the way to do this is surround the variable assignment with ' quotes, I tried to escape the string like this:

UNZIP_FOUND='$(dpkg-query -W --showformat=\'${Status}\n\' unzip|grep "install ok installed")'

but it doesn't work, probably my escaping was bad.

I have this shell script:

UNZIP_FOUND=$(dpkg-query -W --showformat='${Status}\n' unzip|grep "install ok installed")
    if [ "" == "$UNZIP_FOUND" ]; then
        echo unzip not found, I will install it
        apt-get --assume-yes install unzip > /dev/null
    fi

However this produces me a sentence each time:

dpkg-query: no packages found matching unzip

Before running the actual installation step, there's a way to get rid of it ?

I need to just assign the value of dkpg-query command inside the UNZIP_FOUND variable but I don't want to echo it.

I read that the way to do this is surround the variable assignment with ' quotes, I tried to escape the string like this:

UNZIP_FOUND='$(dpkg-query -W --showformat=\'${Status}\n\' unzip|grep "install ok installed")'

but it doesn't work, probably my escaping was bad.

I have this shell script:

UNZIP_FOUND=$(dpkg-query -W --showformat='${Status}\n' unzip|grep "install ok installed")
    if [ "" == "$UNZIP_FOUND" ]; then
        echo unzip not found, I will install it
        apt-get --assume-yes install unzip > /dev/null
    fi

However this produces me a sentence each time:

dpkg-query: no packages found matching unzip

before running the actual installation step.

Is there a way to get rid of it ?

I need to just assign the value of dkpg-query command inside the UNZIP_FOUND variable but I don't want to echo it.

I read that the way to do this is surround the variable assignment with ' quotes, I tried to escape the string like this:

UNZIP_FOUND='$(dpkg-query -W --showformat=\'${Status}\n\' unzip|grep "install ok installed")'

but it doesn't work, probably my escaping was bad.

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 267
Source Link
user3450548
  • 3.1k
  • 13
  • 37
  • 56

Escape correctly this variable string so it doens't output

I have this shell script:

UNZIP_FOUND=$(dpkg-query -W --showformat='${Status}\n' unzip|grep "install ok installed")
    if [ "" == "$UNZIP_FOUND" ]; then
        echo unzip not found, I will install it
        apt-get --assume-yes install unzip > /dev/null
    fi

However this produces me a sentence each time:

dpkg-query: no packages found matching unzip

Before running the actual installation step, there's a way to get rid of it ?

I need to just assign the value of dkpg-query command inside the UNZIP_FOUND variable but I don't want to echo it.

I read that the way to do this is surround the variable assignment with ' quotes, I tried to escape the string like this:

UNZIP_FOUND='$(dpkg-query -W --showformat=\'${Status}\n\' unzip|grep "install ok installed")'

but it doesn't work, probably my escaping was bad.