bash - Get rid of "warning: command substitution: ignored null byte in input" -


i'm getting -bash: warning: command substitution: ignored null byte in input when run model=$(cat /proc/device-tree/model)

bash --version gnu bash, version 4.4.12(1)-release (arm-unknown-linux-gnueabihf) 

with bash version 4.3.30 it's ok

i understand problem terminating \0 character in file, how can suppress stupid message? whole script messed since i'm on bash 4.4

there 2 possible behaviors might want here:

  • read until first nul. more performant approach, requires no external processes shell. checking whether destination variable non-empty after failure ensures successful exit status in case content read no nul exists in input (which otherwise result in nonzero exit status).

    ifs= read -r -d '' model </proc/device-tree/model || [[ $model ]] 
  • read ignoring nuls. gets equivalent behavior newer (4.4) release of bash.

    model=$(tr -d '\0' </proc/device-tree/model) 

    you implement using builtins follows:

    model="" while ifs= read -r -d '' substring || [[ $substring ]];   model+="$substring" done </proc/device-tree/model 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -